use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class AbstractLocalDevBimServerStarter method start.
public void start(int id, String address, String name, int port, int pbport, Path[] pluginDirectories, Path home, ResourceFetcher resourceFetcher, String resourceBase, boolean autoSetup) {
BimServerConfig config = new BimServerConfig();
if (home != null) {
config.setHomeDir(home);
} else {
config.setHomeDir(Paths.get("tmptestdata/home" + (id == -1 ? "" : id)));
}
config.setResourceFetcher(resourceFetcher);
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.setResourceBase(resourceBase);
Path bdbPropertiesFile = config.getHomeDir().resolve("bdb.properties");
if (Files.exists(bdbPropertiesFile)) {
try (InputStream inputStream = Files.newInputStream(bdbPropertiesFile)) {
Properties properties = new Properties();
properties.load(inputStream);
config.setBdbEnvironmentProperties(properties);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
fixLogging(config);
} catch (IOException e1) {
e1.printStackTrace();
}
bimServer = new BimServer(config);
bimServer.getVersionChecker().getLocalVersion().setDate(new Date());
bimServer.setEmbeddedWebServer(new EmbeddedWebServer(bimServer, config.getResourcebase(), 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.getPluginBundleManager(), pluginDirectories);
} catch (PluginException e) {
LOGGER.error("", e);
}
}
}
});
} else if (bimServer.getServerInfo().getServerState() == ServerState.RUNNING) {
long start = System.nanoTime();
LOGGER.info("Loading plugins...");
LocalDevPluginLoader.loadPlugins(bimServer.getPluginBundleManager(), pluginDirectories);
bimServer.activateServices();
long end = System.nanoTime();
LOGGER.info("All plugins loaded (" + ((end - start) / 1000000) + " ms)");
} else if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginBundleManager(), pluginDirectories);
if (autoSetup) {
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.ServiceException in project BIMserver by opensourceBIM.
the class ServiceImpl method initiateCheckin.
@Override
public Long initiateCheckin(Long poid, Long deserializerOid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
ProgressOnProjectTopic progressTopic = getBimServer().getNotificationsManager().createProgressOnProjectTopic(getAuthorization().getUoid(), poid, SProgressTopicType.UPLOAD, "Checkin");
long topicId = progressTopic.getKey().getId();
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
Project tmpProject = tmpSession.get(poid, OldQuery.getDefault());
if (tmpProject.getCheckinInProgress() != topicId && tmpProject.getCheckinInProgress() != 0) {
Thread.sleep(1000);
throw new UserException("Checkin in progress on this project (topicId: " + tmpProject.getCheckinInProgress() + "), please try again later");
}
tmpProject.setCheckinInProgress(topicId);
tmpSession.store(tmpProject);
tmpSession.commit();
} catch (BimserverDatabaseException e) {
// TODO
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ServiceException e) {
if (e instanceof UserException) {
throw (UserException) e;
}
e.printStackTrace();
}
final DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
Project project = session.get(poid, OldQuery.getDefault());
if (!getAuthorization().hasRightsOnProjectOrSuperProjects(user, project)) {
throw new UserException("User has no rights to checkin models to this project");
}
if (!MailSystem.isValidEmailAddress(user.getUsername())) {
throw new UserException("Users must have a valid e-mail address to checkin");
}
if (project == null) {
throw new UserException("No project found with poid " + poid);
}
return progressTopic.getKey().getId();
} catch (UserException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("", e);
throw new ServerException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class TestAddExtendedData method start.
private void start() {
try {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SFile file = new SFile();
file.setData("test".getBytes(Charsets.UTF_8));
file.setMime("text");
file.setFilename("test.txt");
long fileId = client.getServiceInterface().uploadFile(file);
SProject project = client.getServiceInterface().addProject("t2es035442t23", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "initial", deserializerForExtension.getOid(), false, Paths.get("../../TestFiles/TestData/data/AC11-FZK-Haus-IFC.ifc"));
SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("GEOMETRY_GENERATION_REPORT_JSON_1_1");
SExtendedData extendedData = new SExtendedData();
extendedData.setFileId(fileId);
extendedData.setTitle("test3");
extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
client.getServiceInterface().addExtendedDataToRevision(checkinSync.getRoid(), extendedData);
} catch (ServiceException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations