Search in sources :

Example 51 with ServiceException

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);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) ServerState(org.bimserver.models.store.ServerState) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) Properties(java.util.Properties) Logger(org.slf4j.Logger) Date(java.util.Date) PluginException(org.bimserver.shared.exceptions.PluginException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException)

Example 52 with ServiceException

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();
    }
}
Also used : Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ProgressOnProjectTopic(org.bimserver.notifications.ProgressOnProjectTopic) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) ServerException(org.bimserver.shared.exceptions.ServerException) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException)

Example 53 with ServiceException

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();
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) SExtendedData(org.bimserver.interfaces.objects.SExtendedData) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IOException(java.io.IOException) SFile(org.bimserver.interfaces.objects.SFile) SProject(org.bimserver.interfaces.objects.SProject) SExtendedDataSchema(org.bimserver.interfaces.objects.SExtendedDataSchema)

Aggregations

ServiceException (org.bimserver.shared.exceptions.ServiceException)53 IOException (java.io.IOException)21 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)21 SProject (org.bimserver.interfaces.objects.SProject)19 DatabaseSession (org.bimserver.database.DatabaseSession)18 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)17 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)16 User (org.bimserver.models.store.User)13 Project (org.bimserver.models.store.Project)11 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)11 UserException (org.bimserver.shared.exceptions.UserException)11 Date (java.util.Date)10 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)9 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)9 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)9 Path (java.nio.file.Path)8 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)8 ServerException (org.bimserver.shared.exceptions.ServerException)8 ArrayList (java.util.ArrayList)6 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)6