use of org.bimserver.BimServerConfig in project BIMserver by opensourceBIM.
the class AllTests method setup.
private static void setup() {
// Create a config
Path home = Paths.get("tmptestdata/home-" + new Random().nextInt(1000000000));
// Remove the home dir if it's there
if (Files.exists(home)) {
try {
PathUtils.removeDirectoryWithContent(home);
} catch (IOException e) {
e.printStackTrace();
}
}
BimServerConfig config = new BimServerConfig();
config.setHomeDir(home);
config.setStartEmbeddedWebServer(true);
config.setPort(7010);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
config.setClassPath(System.getProperty("java.class.path"));
bimServer = new BimServer(config);
try {
bimServer.setEmbeddedWebServer(new EmbeddedWebServer(bimServer, Paths.get("."), false));
// CHANGE THESE TO MATCH YOUR CONFIGURATION
// Path[] pluginDirectories = new Path[]{Paths.get("C:\\Git\\IfcPlugins\\IfcPlugins"), Paths.get("C:\\Git\\IfcOpenShell-BIMserver-plugin")};
// Start it
bimServer.start();
// Load plugins
// LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
// Get a client, not using any protocol (direct connection)
BimServerClientInterface client = bimServer.getBimServerClientFactory().create();
// Setup the server
client.getAdminInterface().setup("http://localhost:7010", "Test Name", "Test Description", "noicon", "Administrator", "admin@bimserver.org", "admin");
ServiceMap serviceMap = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL);
serviceMap.getSettingsInterface().setCacheOutputFiles(false);
client.disconnect();
client = bimServer.getBimServerClientFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
String pluginsString = System.getProperty("plugins");
if (pluginsString != null) {
String[] plugins = pluginsString.split(";");
Path[] paths = new Path[plugins.length];
int i = 0;
for (String p : plugins) {
paths[i++] = Paths.get(p);
}
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), paths);
} else {
LoggerFactory.getLogger(AllTests.class).info("Installing plugins");
client.getPluginInterface().installPluginBundle("http://archiva.logic-labs.nl/repository/snapshots", "org.opensourcebim", "ifcplugins", null, null);
client.getPluginInterface().installPluginBundle("http://archiva.logic-labs.nl/repository/snapshots", "org.opensourcebim", "binaryserializers", null, null);
client.getPluginInterface().installPluginBundle("http://archiva.logic-labs.nl/repository/snapshots", "org.opensourcebim", "ifcopenshellplugin", null, null);
}
client.disconnect();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.bimserver.BimServerConfig in project BIMserver by opensourceBIM.
the class TestInOut method start.
private void start(String[] args) {
BimServerConfig config = new BimServerConfig();
Path homeDir = Paths.get("home");
try {
if (Files.isDirectory(homeDir)) {
PathUtils.removeDirectoryWithContent(homeDir);
}
} catch (IOException e) {
e.printStackTrace();
}
config.setClassPath(System.getProperty("java.class.path"));
config.setHomeDir(homeDir);
config.setPort(8080);
config.setStartEmbeddedWebServer(true);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), new OptionsParser(args).getPluginDirectories());
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
adminInterface.setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
settingsInterface.setCacheOutputFiles(false);
}
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SProject project = client.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path inputFile = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
client.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, inputFile);
project = client.getServiceInterface().getProjectByPoid(project.getOid());
SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
Path outputFile = Paths.get("output.ifc");
client.download(project.getLastRevisionId(), serializer.getOid(), outputFile);
Diff diff = new Diff(false, false, false, inputFile, outputFile);
diff.start();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (PluginException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (CompareException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
e.printStackTrace();
}
}
use of org.bimserver.BimServerConfig in project BIMserver by opensourceBIM.
the class WarServerInitializer method contextInitialized.
public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
Path homeDir = null;
if (servletContext.getAttribute("homedir") != null) {
homeDir = Paths.get((String) servletContext.getAttribute("homedir"));
}
if (homeDir == null && servletContext.getInitParameter("homedir") != null) {
homeDir = Paths.get(servletContext.getInitParameter("homedir"));
}
boolean autoMigrate = false;
if (servletContext.getAttribute("autoMigrate") != null) {
autoMigrate = (Boolean) servletContext.getAttribute("autoMigrate");
}
if (autoMigrate == false && servletContext.getInitParameter("autoMigrate") != null) {
autoMigrate = Boolean.valueOf(servletContext.getInitParameter("autoMigrate"));
}
String realPath = servletContext.getRealPath("/");
if (!realPath.endsWith("/")) {
realPath = realPath + "/";
}
Path baseDir = Paths.get(realPath + "WEB-INF");
if (homeDir == null) {
homeDir = baseDir;
}
ResourceFetcher resourceFetcher = new WarResourceFetcher(servletContext, homeDir);
BimServerConfig config = new BimServerConfig();
config.setAutoMigrate(autoMigrate);
config.setEnvironment(Environment.WAR);
config.setHomeDir(homeDir);
config.setResourceFetcher(resourceFetcher);
if (homeDir != null) {
// Basically doing this twice (also in BimServer.init), but this makes sure the logback.xml file is copied to the homedir
try {
BimServer.initHomeDir(config);
} catch (IOException e) {
e.printStackTrace();
}
}
setupLogging(homeDir);
try {
fixLogging(config);
config.setClassPath(makeClassPath(resourceFetcher.getFile("lib")));
} catch (IOException e1) {
e1.printStackTrace();
}
config.setStartEmbeddedWebServer(false);
bimServer = new BimServer(config);
Jsr356Impl.setDefaultServletContext(servletContextEvent.getServletContext());
Logger LOGGER = LoggerFactory.getLogger(WarServerInitializer.class);
LOGGER.info("Servlet Context Name: " + servletContext.getServletContextName());
try {
bimServer.start();
} catch (ServerException e) {
LOGGER.error("", e);
} catch (DatabaseInitException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (PluginException e) {
LOGGER.error("", e);
} catch (DatabaseRestartRequiredException e) {
LOGGER.error("", e);
}
servletContext.setAttribute("bimserver", bimServer);
}
use of org.bimserver.BimServerConfig in project BIMserver by opensourceBIM.
the class TestIfcEngineEmbedded method main.
public static void main(String[] args) {
// Create a config
BimServerConfig config = new BimServerConfig();
Path home = Paths.get("home");
// Remove the home dir if it's there
if (WIPE_HOMEDIR) {
try {
PathUtils.removeDirectoryWithContent(home);
} catch (IOException e) {
e.printStackTrace();
}
}
config.setHomeDir(home);
config.setStartEmbeddedWebServer(true);
config.setPort(8080);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
config.setClassPath(System.getProperty("java.class.path"));
// Create a BIMserver
BimServer bimServer = new BimServer(config);
BimServerClientInterface client = null;
try {
// Load plugins
Path[] pluginDirs = new Path[] {// TODO: Set these up yourself...
};
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirs);
// Start it
bimServer.start();
// Get a client, not using any protocol (direct connection)
client = bimServer.getBimServerClientFactory().create();
// Setup the server
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
client.getAdminInterface().setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
}
// Authenticate
client.setAuthentication(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Iterate over the IfcEngines and see if there is one matching the classname specified above
boolean engineFound = false;
for (SRenderEnginePluginConfiguration conf : client.getPluginInterface().getAllRenderEngines(false)) {
SPluginDescriptor pluginDescriptor = client.getPluginInterface().getPluginDescriptor(conf.getPluginDescriptorId());
if (RENDER_ENGINE.equals(pluginDescriptor.getPluginClassName())) {
client.getPluginInterface().setDefaultRenderEngine(conf.getOid());
engineFound = true;
LOGGER.info("Using " + conf.getName());
break;
}
}
if (!engineFound) {
throw new RenderEngineException("No IfcEnginePlugin found with name " + RENDER_ENGINE);
}
// Get a deserializer
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", -1L);
if (deserializer == null) {
throw new Exception("No deserializer found for IFC-SPF. Make sure plugin directories are correctly configured");
}
Thread[] threads = new Thread[TEST_FILES.length];
AddProjectCheckinDownloadAction[] contexts = new AddProjectCheckinDownloadAction[TEST_FILES.length];
for (int i = 0; i < TEST_FILES.length; ++i) {
(threads[i] = new Thread(contexts[i] = new AddProjectCheckinDownloadAction(bimServer, TEST_FILES[i]))).start();
}
for (int i = 0; i < TEST_FILES.length; ++i) {
threads[i].join();
}
for (int i = 0; i < TEST_FILES.length; ++i) {
contexts[i].verify();
}
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
try {
client.disconnect();
} catch (Throwable t) {
}
try {
bimServer.stop();
} catch (Throwable t) {
}
}
}
use of org.bimserver.BimServerConfig in project BIMserver by opensourceBIM.
the class TestSimultaniousDownloadWithCaching method start.
private void start() {
BimServerConfig config = new BimServerConfig();
Path homeDir = Paths.get("home");
try {
if (Files.isDirectory(homeDir)) {
PathUtils.removeDirectoryWithContent(homeDir);
}
} catch (IOException e) {
e.printStackTrace();
}
config.setClassPath(System.getProperty("java.class.path"));
config.setHomeDir(homeDir);
config.setPort(8080);
config.setStartEmbeddedWebServer(true);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
final BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
}
} catch (PluginException e2) {
e2.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
try {
final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
settingsInterface.setCacheOutputFiles(true);
settingsInterface.setGenerateGeometryOnCheckin(false);
final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
for (int i = 0; i < 20; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
c.writeToOutputStream(baos, null);
System.out.println(baos.size());
} catch (SerializerException e) {
e.printStackTrace();
}
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(downloadData.getFile().getInputStream(), baos);
System.out.println(baos.size());
}
serviceMap2.getServiceInterface().cleanupLongAction(download);
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.HOURS);
bimServer.stop();
} catch (ServerException e1) {
e1.printStackTrace();
} catch (UserException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e2) {
e2.printStackTrace();
}
}
Aggregations