use of org.bimserver.shared.exceptions.PluginException 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.shared.exceptions.PluginException in project BIMserver by opensourceBIM.
the class DownloadQueryDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
BimDatabaseAction<IfcModelInterface> action = new DownloadDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, roid, -1, serializerPluginConfiguration.getOid(), getAuthorization(), null);
IfcModelInterface ifcModel = session.executeAndCommitAction(action);
QueryEnginePluginConfiguration queryEngineObject = session.get(StorePackage.eINSTANCE.getQueryEnginePluginConfiguration(), qeid, OldQuery.getDefault());
Revision revision = session.get(roid, OldQuery.getDefault());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
if (objectIDM == null) {
objectIDM = new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), packageMetaData);
}
if (queryEngineObject != null) {
QueryEnginePlugin queryEnginePlugin = getBimServer().getPluginManager().getQueryEngine(queryEngineObject.getPluginDescriptor().getPluginClassName(), true);
if (queryEnginePlugin != null) {
QueryEngine queryEngine = queryEnginePlugin.getQueryEngine(new PluginConfiguration(queryEngineObject.getSettings()));
final IfcModelInterface result = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
ModelHelper modelHelper = new ModelHelper(getBimServer().getMetaDataManager(), objectIDM, result);
modelHelper.setOidProvider(new OidProvider() {
private long oid = 1000000;
@Override
public long newOid(EClass eClass) {
return oid++;
}
});
IfcModelInterface finalResult = queryEngine.query(ifcModel, code, new Reporter() {
@Override
public void error(Throwable error) {
}
@Override
public void warning(String warning) {
}
@Override
public void info(String info) {
}
}, modelHelper);
return finalResult;
} else {
throw new UserException("No Query Engine found " + queryEngineObject.getPluginDescriptor().getPluginClassName());
}
} else {
throw new UserException("No configured query engine found with qeid " + qeid);
}
} catch (BimserverDatabaseException e) {
throw new UserException(e);
} catch (QueryEngineException e) {
throw new UserException(e);
} catch (PluginException e) {
throw new UserException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.
the class TriggerImportDataRemote method main.
public static void main(String[] args) {
/*
* Args:
* 0: Address of new server
* 1: Username
* 2: Password
* 3: Address of old server
* 4: Local path to incoming folder of old server, this local path has to be available on the new server, so you have to copy it from the old server
*/
try {
Path home = Paths.get("home");
Path tmp = home.resolve("tmp");
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
MetaDataManager metaDataManager = new MetaDataManager(tmp);
pluginManager.setMetaDataManager(metaDataManager);
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, args[0])) {
BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo(args[1], args[2]));
client.getServiceInterface().importData(args[3], args[1], args[2], args[4]);
} catch (Exception e) {
e.printStackTrace();
}
} catch (PluginException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
}
}
use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.
the class LocalDevBimServerStarter method start.
public void start(int id, String address, String name, int port, int pbport, Path[] pluginDirectories, Path home) {
BimServerConfig config = new BimServerConfig();
if (home != null) {
config.setHomeDir(home);
} else {
config.setHomeDir(Paths.get("tmptestdata/home" + (id == -1 ? "" : id)));
}
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
config.setStartEmbeddedWebServer(true);
config.setClassPath(System.getProperty("java.class.path"));
config.setLocalDev(true);
config.setEnvironment(Environment.LOCAL_DEV);
config.setPort(port);
config.setStartCommandLine(true);
config.setDevelopmentBaseDir(Paths.get("../BimServer"));
try {
fixLogging(config);
} catch (IOException e1) {
e1.printStackTrace();
}
bimServer = new BimServer(config);
bimServer.getVersionChecker().getLocalVersion().setDate(new Date());
bimServer.setEmbeddedWebServer(new EmbeddedWebServer(bimServer, config.getDevelopmentBaseDir(), config.isLocalDev()));
Logger LOGGER = LoggerFactory.getLogger(LocalDevBimServerStarter.class);
try {
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.MIGRATION_REQUIRED) {
bimServer.getServerInfoManager().registerStateChangeListener(new StateChangeListener() {
@Override
public void stateChanged(ServerState oldState, ServerState newState) {
if (oldState == ServerState.MIGRATION_REQUIRED && newState == ServerState.RUNNING) {
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
} catch (PluginException e) {
LOGGER.error("", e);
}
}
}
});
} else if (bimServer.getServerInfo().getServerState() == ServerState.RUNNING || bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
try {
AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
adminInterface.setup("http://localhost:" + port, name, "My Description", "http://localhost:" + port + "/img/bimserver.png", "Administrator", "admin@bimserver.org", "admin");
SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
settingsInterface.setCacheOutputFiles(false);
settingsInterface.setPluginStrictVersionChecking(false);
} catch (Exception e) {
// Ignore
}
bimServer.activateServices();
} else {
LOGGER.error("BIMserver did not startup correctly");
}
} catch (PluginException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (DatabaseInitException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (DatabaseRestartRequiredException e) {
LOGGER.error("", e);
}
}
use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.
the class ServiceRunnerServlet method service.
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (request.getRequestURI().endsWith("/servicelist")) {
processServiceList(request, response);
return;
}
String token = null;
if (request.getHeader("Authorization") != null) {
String a = request.getHeader("Authorization");
if (a.startsWith("Bearer")) {
token = a.substring(7);
}
}
if (token == null) {
token = request.getHeader("Token");
}
LOGGER.info("Token: " + token);
String serviceName = request.getHeader("ServiceName");
if (serviceName == null) {
serviceName = request.getRequestURI();
if (serviceName.startsWith("/services/")) {
serviceName = serviceName.substring(10);
}
}
LOGGER.info("ServiceName: " + serviceName);
long serviceOid = Long.parseLong(serviceName);
String inputType = request.getHeader("Input-Type");
LOGGER.info("Input-Type: " + inputType);
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
Authorization authorization = Authorization.fromToken(getBimServer().getEncryptionKey(), token);
User user = session.get(authorization.getUoid(), OldQuery.getDefault());
if (user == null) {
LOGGER.error("Service \"" + serviceName + "\" not found for this user");
throw new UserException("No user found with uoid " + authorization.getUoid());
}
if (user.getState() == ObjectState.DELETED) {
LOGGER.error("User has been deleted");
throw new UserException("User has been deleted");
}
InternalServicePluginConfiguration foundService = null;
UserSettings userSettings = user.getUserSettings();
for (InternalServicePluginConfiguration internalServicePluginConfiguration : userSettings.getServices()) {
if (internalServicePluginConfiguration.getOid() == serviceOid) {
foundService = internalServicePluginConfiguration;
break;
}
}
if (foundService == null) {
LOGGER.info("Service \"" + serviceName + "\" not found for this user");
throw new ServletException("Service \"" + serviceName + "\" not found for this user");
}
PluginDescriptor pluginDescriptor = foundService.getPluginDescriptor();
ServicePlugin servicePlugin = getBimServer().getPluginManager().getServicePlugin(pluginDescriptor.getPluginClassName(), true);
if (servicePlugin instanceof BimBotsServiceInterface) {
LOGGER.info("Found service " + servicePlugin);
BimBotsServiceInterface bimBotsServiceInterface = (BimBotsServiceInterface) servicePlugin;
try {
if (getBimServer().getServerSettingsCache().getServerSettings().isStoreServiceRuns()) {
LOGGER.info("Storing intermediate results");
// When we store service runs, we can just use the streaming deserializer to stream directly to the database, after that we'll trigger the actual service
// Create or find project and link user and service to project
// Checkin stream into project
// Trigger service
ServiceInterface serviceInterface = getBimServer().getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
SProject project = serviceInterface.addProject("tmp-" + new Random().nextInt(), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = serviceInterface.getSuggestedDeserializerForExtension("ifc", project.getOid());
if (deserializer == null) {
throw new BimBotsException("No deserializer found");
}
serviceInterface.checkin(project.getOid(), "Auto checkin", deserializer.getOid(), -1L, "s", new DataHandler(new InputStreamDataSource(request.getInputStream())), false, true);
project = serviceInterface.getProjectByPoid(project.getOid());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
try {
Revision revision = session.get(project.getLastRevisionId(), OldQuery.getDefault());
session.getMap(model, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid(), null, Deep.NO));
} catch (BimserverDatabaseException e) {
e.printStackTrace();
}
BimServerBimBotsInput input = new BimServerBimBotsInput(getBimServer(), authorization.getUoid(), null, null, model);
BimBotsOutput output = bimBotsServiceInterface.runBimBot(input, getBimServer().getSConverter().convertToSObject(foundService.getSettings()));
SExtendedData extendedData = new SExtendedData();
SFile file = new SFile();
file.setData(output.getData());
file.setFilename(output.getContentDisposition());
file.setMime(output.getContentType());
file.setSize(output.getData().length);
Long fileId = serviceInterface.uploadFile(file);
extendedData.setFileId(fileId);
extendedData.setTitle(output.getTitle());
SExtendedDataSchema extendedDataSchema = null;
try {
extendedDataSchema = serviceInterface.getExtendedDataSchemaByName(output.getSchemaName());
} catch (UserException e) {
extendedDataSchema = new SExtendedDataSchema();
extendedDataSchema.setContentType(output.getContentType());
extendedDataSchema.setName(output.getSchemaName());
serviceInterface.addExtendedDataSchema(extendedDataSchema);
}
extendedData.setSchemaId(extendedDataSchema.getOid());
serviceInterface.addExtendedDataToRevision(project.getLastRevisionId(), extendedData);
response.setHeader("Output-Type", output.getSchemaName());
response.setHeader("Data-Title", output.getTitle());
response.setHeader("Data-Identifier", "" + project.getOid());
response.setHeader("Content-Type", output.getContentType());
response.setHeader("Content-Disposition", output.getContentDisposition());
response.getOutputStream().write(output.getData());
} else {
// When we don't store the service runs, there is no other way than to just use the old deserializer and run the service from the EMF model
LOGGER.info("NOT Storing intermediate results");
DeserializerPlugin deserializerPlugin = getBimServer().getPluginManager().getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
if (deserializerPlugin == null) {
throw new BimBotsException("No deserializer plugin found");
}
byte[] data = IOUtils.toByteArray(request.getInputStream());
SchemaName schema = SchemaName.valueOf(inputType);
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData("ifc2x3tc1");
deserializer.init(packageMetaData);
IfcModelInterface model = deserializer.read(new ByteArrayInputStream(data), schema.name(), data.length, null);
BimServerBimBotsInput input = new BimServerBimBotsInput(getBimServer(), authorization.getUoid(), schema, data, model);
BimBotsOutput output = bimBotsServiceInterface.runBimBot(input, getBimServer().getSConverter().convertToSObject(foundService.getSettings()));
response.setHeader("Output-Type", output.getSchemaName());
response.setHeader("Data-Title", output.getTitle());
response.setHeader("Content-Type", output.getContentType());
response.setHeader("Content-Disposition", output.getContentDisposition());
response.getOutputStream().write(output.getData());
}
} catch (BimBotsException e) {
LOGGER.error("", e);
} catch (DeserializeException e) {
LOGGER.error("", e);
} catch (PluginException e) {
LOGGER.error("", e);
} catch (ServerException e) {
LOGGER.error("", e);
}
} else {
throw new ServletException("Service \"" + serviceName + "\" does not implement the BimBotsServiceInterface");
}
} catch (AuthenticationException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (UserException e) {
LOGGER.error("", e);
}
}
Aggregations