use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class ServiceImpl method getSuggestedDeserializerForExtension.
@Override
public SDeserializerPluginConfiguration getSuggestedDeserializerForExtension(String extension, Long poid) throws ServerException, UserException {
if (extension.startsWith(".")) {
extension = extension.substring(1);
}
// Token authenticated users should also be able to call this method
try {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
List<DeserializerPluginConfiguration> list = new ArrayList<>();
try {
Project project = session.get(poid, OldQuery.getDefault());
UserSettings userSettings = getUserSettings(session);
for (DeserializerPluginConfiguration deserializer : userSettings.getDeserializers()) {
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializer.getPluginDescriptor().getIdentifier(), true);
if (plugin instanceof DeserializerPlugin) {
DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
if (deserializerPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
if (deserializerPlugin.canHandleExtension(extension)) {
list.add(deserializer);
}
}
} else if (plugin instanceof StreamingDeserializerPlugin) {
StreamingDeserializerPlugin streamingDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
if (streamingDeserializerPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
if (streamingDeserializerPlugin.canHandleExtension(extension)) {
list.add(deserializer);
}
}
}
}
} finally {
session.close();
}
if (list.size() == 1) {
return getBimServer().getSConverter().convertToSObject(list.get(0));
} else if (list.size() > 1) {
for (DeserializerPluginConfiguration deserializerPluginConfiguration : list) {
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getIdentifier(), true);
// Prefer the streaming version
if (plugin instanceof StreamingDeserializerPlugin) {
return getBimServer().getSConverter().convertToSObject(deserializerPluginConfiguration);
}
}
// Just return the first one
return getBimServer().getSConverter().convertToSObject(list.get(0));
}
} catch (Exception e) {
return handleException(e);
}
return null;
}
use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class BimServerClient method getGeometry.
@Override
public Geometry getGeometry(long roid, IdEObject ifcProduct) {
try {
SSerializerPluginConfiguration serializerByPluginClassName = getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometrySerializerPlugin");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
download(roid, serializerByPluginClassName.getOid(), outputStream);
Files.write(Paths.get("bin.bin"), outputStream.toByteArray());
ByteArrayInputStream bain = new ByteArrayInputStream(outputStream.toByteArray());
return new Geometry(bain, ifcProduct.getOid());
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
e.printStackTrace();
}
return null;
}
use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class StreamingModel method processDownload.
private void processDownload(Long topicId) throws UserException, ServerException, PublicInterfaceNotFoundException, IfcModelInterfaceException, IOException {
InputStream inputStream = bimServerClient.getDownloadData(topicId);
if (inputStream == null) {
throw new IfcModelInterfaceException("No InputStream to read from for topicId " + topicId);
}
InputStream downloadData = new org.bimserver.utils.CountingInputStream(inputStream) {
};
try {
JsonFactory jsonFactory = new JsonFactory();
JsonParser jp = jsonFactory.createParser(downloadData);
// TODO implement
} catch (Exception e) {
throw new IfcModelInterfaceException(e);
} finally {
if (downloadData != null) {
downloadData.close();
}
}
}
use of org.bimserver.shared.exceptions.ServerException 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);
// TODO
// 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.ServerException in project BIMserver by opensourceBIM.
the class DownloadByNewQueryDatabaseAction method execute.
@Override
public ObjectProvider execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
User user = getUserByUoid(authorization.getUoid());
Project project = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
for (Long roid : roids) {
Revision virtualRevision = getRevisionByRoid(roid);
pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
project = virtualRevision.getProject();
try {
authorization.canDownload(roid);
} catch (UserException e) {
if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
throw new UserException("User has insufficient rights to download revisions from this project");
}
if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
throw new UserException("User has insufficient rights to download revisions from this project");
}
}
}
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
try {
return QueryObjectProvider.fromJsonString(getDatabaseSession(), bimServer, json, roids, packageMetaData);
} catch (Exception e) {
throw new UserException(e);
}
}
Aggregations