Search in sources :

Example 21 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);
        System.out.println(client.getServiceInterface().getFile(fileId));
        SProject project = client.getServiceInterface().addProject("test23", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        client.checkin(project.getOid(), "initial", deserializerForExtension.getOid(), false, Flow.SYNC, Paths.get("../TestData/data/AC11-FZK-Haus-IFC.ifc"));
        project = client.getServiceInterface().getProjectByPoid(project.getOid());
        SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("http://extend.bimserver.org/validationreport");
        SExtendedData extendedData = new SExtendedData();
        extendedData.setFileId(fileId);
        extendedData.setTitle("test3");
        extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
        client.getServiceInterface().addExtendedDataToRevision(project.getLastRevisionId(), 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) 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)

Example 22 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class JsonHandler method handleThrowable.

private void handleThrowable(JsonWriter writer, Throwable throwable) {
    if (!(throwable instanceof ServiceException)) {
        LoggerFactory.getLogger(JsonHandler.class).error("", throwable);
    } else {
        if (LoggerFactory.getLogger(JsonHandler.class).isDebugEnabled()) {
            LoggerFactory.getLogger(JsonHandler.class).debug("", throwable);
        }
    }
    try {
        writer.beginObject();
        writer.name("exception");
        writer.beginObject();
        writer.name("__type");
        writer.value(throwable.getClass().getSimpleName());
        writer.name("message");
        writer.value(throwable.getMessage() == null ? throwable.toString() : throwable.getMessage());
        if (throwable instanceof ServiceException) {
            ServiceException serviceException = (ServiceException) throwable;
            if (serviceException.getErrorCode() != null) {
                writer.name("errorCode");
                writer.value(serviceException.getErrorCode().getCode());
            }
        }
        writer.endObject();
        writer.endObject();
    } catch (IOException e) {
        LOGGER.error("", e);
    }
}
Also used : ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException)

Example 23 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class LocalDevSetup method setupJson.

/**
 * @param address
 * @return
 */
@SuppressWarnings("resource")
public static final BimServerClientInterface setupJson(String address) {
    try {
        Path home = Paths.get("home");
        if (!Files.isDirectory(home)) {
            Files.createDirectory(home);
        }
        Path tmp = home.resolve("tmp");
        if (!Files.isDirectory(tmp)) {
            Files.createDirectory(tmp);
        }
        MavenPluginRepository mavenPluginRepository = new MavenPluginRepository();
        PluginManager pluginManager = new PluginManager(tmp, System.getProperty("java.class.path"), null, null, null, null);
        PluginBundleManager pluginBundleManager = new PluginBundleManager(pluginManager, mavenPluginRepository, home.resolve("plugins"));
        pluginBundleManager.loadAllPluginsFromEclipseWorkspace(Paths.get("../"), true);
        MetaDataManager metaDataManager = new MetaDataManager(tmp);
        pluginManager.setMetaDataManager(metaDataManager);
        metaDataManager.init(false);
        pluginManager.initAllLoadedPlugins();
        BimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, address);
        return factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
    } catch (PluginException e) {
        LOGGER.error("", e);
    } catch (ServiceException e) {
        LOGGER.error("", e);
    } catch (ChannelConnectionException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (BimServerClientException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : Path(java.nio.file.Path) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) PluginException(org.bimserver.shared.exceptions.PluginException) MetaDataManager(org.bimserver.emf.MetaDataManager) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ProtocolBuffersBimServerClientFactory(org.bimserver.client.protocolbuffers.ProtocolBuffersBimServerClientFactory) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) SoapBimServerClientFactory(org.bimserver.client.soap.SoapBimServerClientFactory) PluginManager(org.bimserver.plugins.PluginManager) PluginBundleManager(org.bimserver.plugins.PluginBundleManager) ServiceException(org.bimserver.shared.exceptions.ServiceException) MavenPluginRepository(org.bimserver.plugins.MavenPluginRepository)

Example 24 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class LocalDevSetup method setupProtocolBuffers.

public static final BimServerClientInterface setupProtocolBuffers(String address) {
    Path home = Paths.get("home");
    Path tmp = home.resolve("tmp");
    MetaDataManager metaDataManager = new MetaDataManager(tmp);
    try (BimServerClientFactory factory = new ProtocolBuffersBimServerClientFactory(address, 8000, 8000, null, metaDataManager, new SServicesMap())) {
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        pluginManager.setMetaDataManager(metaDataManager);
        return factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
    } catch (PluginException e) {
        LOGGER.error("", e);
    } catch (ServiceException e) {
        LOGGER.error("", e);
    } catch (ChannelConnectionException e) {
        LOGGER.error("", e);
    } catch (BimServerClientException e) {
        LOGGER.error("", e);
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : Path(java.nio.file.Path) PluginManager(org.bimserver.plugins.PluginManager) SServicesMap(org.bimserver.shared.meta.SServicesMap) ServiceException(org.bimserver.shared.exceptions.ServiceException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) PluginException(org.bimserver.shared.exceptions.PluginException) MetaDataManager(org.bimserver.emf.MetaDataManager) ProtocolBuffersBimServerClientFactory(org.bimserver.client.protocolbuffers.ProtocolBuffersBimServerClientFactory) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ProtocolBuffersBimServerClientFactory(org.bimserver.client.protocolbuffers.ProtocolBuffersBimServerClientFactory) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) SoapBimServerClientFactory(org.bimserver.client.soap.SoapBimServerClientFactory) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PluginException(org.bimserver.shared.exceptions.PluginException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException)

Example 25 with ServiceException

use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.

the class MemoryLeakTester method start.

public void start(int id, String address, int port, int pbport, Path[] pluginDirectories) {
    BimServerConfig config = new BimServerConfig();
    config.setHomeDir(Paths.get("home" + id));
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    config.setStartEmbeddedWebServer(true);
    config.setClassPath(System.getProperty("java.class.path"));
    config.setStartCommandLine(false);
    config.setLocalDev(true);
    config.setPort(port);
    bimServer = new BimServer(config);
    bimServer.getVersionChecker().getLocalVersion().setDate(new Date());
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginBundleManager(), pluginDirectories);
        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:" + port, "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);
        }
        bimServer.stop();
        bimServer = null;
        Thread.sleep(1000000);
    } 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);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : PluginException(org.bimserver.shared.exceptions.PluginException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) Date(java.util.Date) 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)

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