Search in sources :

Example 21 with SDeserializerPluginConfiguration

use of org.bimserver.interfaces.objects.SDeserializerPluginConfiguration in project BIMserver by opensourceBIM.

the class ClientIfcModel method checkin.

public void checkin(long poid, String comment) throws ServerException, UserException, PublicInterfaceNotFoundException {
    this.fixOids(new OidProvider() {

        private long c = 1;

        @Override
        public long newOid(EClass eClass) {
            return c++;
        }
    });
    SharedJsonSerializer sharedJsonSerializer = new SharedJsonSerializer(this, false);
    SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("json", poid);
    bimServerClient.checkin(poid, comment, deserializer.getOid(), false, Flow.SYNC, -1, "test", new SerializerInputstream(sharedJsonSerializer));
}
Also used : SharedJsonSerializer(org.bimserver.emf.SharedJsonSerializer) EClass(org.eclipse.emf.ecore.EClass) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) OidProvider(org.bimserver.emf.OidProvider) SerializerInputstream(org.bimserver.plugins.serializers.SerializerInputstream)

Example 22 with SDeserializerPluginConfiguration

use of org.bimserver.interfaces.objects.SDeserializerPluginConfiguration in project BIMserver by opensourceBIM.

the class BulkUploadServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (request.getHeader("Origin") != null && !getBimServer().getServerSettingsCache().isHostAllowed(request.getHeader("Origin"))) {
        response.setStatus(403);
        return;
    }
    response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
    response.setHeader("Access-Control-Allow-Headers", "Content-Type");
    String token = (String) request.getSession().getAttribute("token");
    ObjectNode result = OBJECT_MAPPER.createObjectNode();
    response.setContentType("text/json");
    try {
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        long poid = -1;
        String comment = null;
        if (isMultipart) {
            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iter = upload.getItemIterator(request);
            InputStream in = null;
            String name = "";
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                if (item.isFormField()) {
                    if ("token".equals(item.getFieldName())) {
                        token = Streams.asString(item.openStream());
                    } else if ("poid".equals(item.getFieldName())) {
                        poid = Long.parseLong(Streams.asString(item.openStream()));
                    } else if ("comment".equals(item.getFieldName())) {
                        comment = Streams.asString(item.openStream());
                    }
                } else {
                    name = item.getName();
                    in = item.openStream();
                    if (poid != -1) {
                        ServiceInterface service = getBimServer().getServiceFactory().get(token, AccessMethod.INTERNAL).get(ServiceInterface.class);
                        SProject mainProject = service.getProjectByPoid(poid);
                        ZipInputStream zipInputStream = new ZipInputStream(in);
                        ZipEntry nextEntry = zipInputStream.getNextEntry();
                        while (nextEntry != null) {
                            String fullfilename = nextEntry.getName();
                            if (fullfilename.toLowerCase().endsWith(".ifc") || fullfilename.toLowerCase().endsWith("ifcxml") || fullfilename.toLowerCase().endsWith(".ifczip")) {
                                InputStreamDataSource inputStreamDataSource = new InputStreamDataSource(new FakeClosingInputStream(zipInputStream));
                                inputStreamDataSource.setName(name);
                                DataHandler ifcFile = new DataHandler(inputStreamDataSource);
                                if (fullfilename.contains("/")) {
                                    String path = fullfilename.substring(0, fullfilename.lastIndexOf("/"));
                                    String filename = fullfilename.substring(fullfilename.lastIndexOf("/") + 1);
                                    String extension = filename.substring(filename.lastIndexOf(".") + 1);
                                    SProject project = getOrCreatePath(service, mainProject, mainProject, path);
                                    SDeserializerPluginConfiguration deserializer = service.getSuggestedDeserializerForExtension(extension, project.getOid());
                                    long topicId = -1;
                                    try {
                                        topicId = service.checkin(project.getOid(), comment, deserializer.getOid(), -1L, filename, ifcFile, false, true);
                                    } finally {
                                        if (topicId != -1) {
                                            service.cleanupLongAction(topicId);
                                        }
                                    }
                                }
                            } else {
                                if (!nextEntry.isDirectory()) {
                                    LOGGER.info("Unknown fileextenstion " + fullfilename);
                                }
                            }
                            nextEntry = zipInputStream.getNextEntry();
                        }
                    // DataHandler ifcFile = new DataHandler(inputStreamDataSource);
                    // 
                    // if (token != null) {
                    // if (topicId == -1) {
                    // long newTopicId = service.checkin(poid, comment, deserializerOid, -1L, name, ifcFile, merge, sync);
                    // result.put("topicId", newTopicId);
                    // } else {
                    // ServiceInterface service = getBimServer().getServiceFactory().get(token, AccessMethod.INTERNAL).get(ServiceInterface.class);
                    // long newTopicId = service.checkinInitiated(topicId, poid, comment, deserializerOid, -1L, name, ifcFile, merge, true);
                    // result.put("topicId", newTopicId);
                    // }
                    // }
                    } else {
                        result.put("exception", "No poid");
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        // sendException(response, e);
        return;
    }
    response.getWriter().write(result.toString());
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ZipInputStream(java.util.zip.ZipInputStream) FakeClosingInputStream(org.opensourcebim.bcf.utils.FakeClosingInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) DataHandler(javax.activation.DataHandler) SProject(org.bimserver.interfaces.objects.SProject) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) InputStreamDataSource(org.bimserver.utils.InputStreamDataSource) ZipInputStream(java.util.zip.ZipInputStream) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) FakeClosingInputStream(org.opensourcebim.bcf.utils.FakeClosingInputStream)

Example 23 with SDeserializerPluginConfiguration

use of org.bimserver.interfaces.objects.SDeserializerPluginConfiguration 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);
    }
}
Also used : ServicePlugin(org.bimserver.plugins.services.ServicePlugin) User(org.bimserver.models.store.User) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DatabaseSession(org.bimserver.database.DatabaseSession) AuthenticationException(org.bimserver.webservices.authorization.AuthenticationException) IfcModelInterface(org.bimserver.emf.IfcModelInterface) DataHandler(javax.activation.DataHandler) BimBotsServiceInterface(org.bimserver.bimbots.BimBotsServiceInterface) SProject(org.bimserver.interfaces.objects.SProject) SExtendedDataSchema(org.bimserver.interfaces.objects.SExtendedDataSchema) Authorization(org.bimserver.webservices.authorization.Authorization) ServletException(javax.servlet.ServletException) InputStreamDataSource(org.bimserver.utils.InputStreamDataSource) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Random(java.util.Random) BimBotsServiceInterface(org.bimserver.bimbots.BimBotsServiceInterface) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) SFile(org.bimserver.interfaces.objects.SFile) ServerException(org.bimserver.shared.exceptions.ServerException) UserSettings(org.bimserver.models.store.UserSettings) PackageMetaData(org.bimserver.emf.PackageMetaData) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) BimBotsException(org.bimserver.bimbots.BimBotsException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) BimServerBimBotsInput(org.bimserver.bimbots.BimServerBimBotsInput) OldQuery(org.bimserver.database.OldQuery) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) Revision(org.bimserver.models.store.Revision) SExtendedData(org.bimserver.interfaces.objects.SExtendedData) ByteArrayInputStream(java.io.ByteArrayInputStream) Deserializer(org.bimserver.plugins.deserializers.Deserializer) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) BimBotsOutput(org.bimserver.bimbots.BimBotsOutput) SchemaName(org.bimserver.plugins.SchemaName)

Example 24 with SDeserializerPluginConfiguration

use of org.bimserver.interfaces.objects.SDeserializerPluginConfiguration in project BIMserver by opensourceBIM.

the class TestIfcEngineEmbedded method main.

public static void main(String[] args) {
    // Create a config
    BimServerConfig config = new BimServerConfig();
    Path home = Paths.get("home");
    // Remove the home dir if it's there
    if (WIPE_HOMEDIR) {
        try {
            PathUtils.removeDirectoryWithContent(home);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    config.setHomeDir(home);
    config.setStartEmbeddedWebServer(true);
    config.setPort(8080);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    config.setClassPath(System.getProperty("java.class.path"));
    // Create a BIMserver
    BimServer bimServer = new BimServer(config);
    BimServerClientInterface client = null;
    try {
        // Load plugins
        Path[] pluginDirs = new Path[] {// TODO: Set these up yourself...
        };
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirs);
        // Start it
        bimServer.start();
        // Get a client, not using any protocol (direct connection)
        client = bimServer.getBimServerClientFactory().create();
        // Setup the server
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            client.getAdminInterface().setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
        }
        // Authenticate
        client.setAuthentication(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Iterate over the IfcEngines and see if there is one matching the classname specified above
        boolean engineFound = false;
        for (SRenderEnginePluginConfiguration conf : client.getPluginInterface().getAllRenderEngines(false)) {
            SPluginDescriptor pluginDescriptor = client.getPluginInterface().getPluginDescriptor(conf.getPluginDescriptorId());
            if (RENDER_ENGINE.equals(pluginDescriptor.getPluginClassName())) {
                client.getPluginInterface().setDefaultRenderEngine(conf.getOid());
                engineFound = true;
                LOGGER.info("Using " + conf.getName());
                break;
            }
        }
        if (!engineFound) {
            throw new RenderEngineException("No IfcEnginePlugin found with name " + RENDER_ENGINE);
        }
        // Get a deserializer
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", -1L);
        if (deserializer == null) {
            throw new Exception("No deserializer found for IFC-SPF. Make sure plugin directories are correctly configured");
        }
        Thread[] threads = new Thread[TEST_FILES.length];
        AddProjectCheckinDownloadAction[] contexts = new AddProjectCheckinDownloadAction[TEST_FILES.length];
        for (int i = 0; i < TEST_FILES.length; ++i) {
            (threads[i] = new Thread(contexts[i] = new AddProjectCheckinDownloadAction(bimServer, TEST_FILES[i]))).start();
        }
        for (int i = 0; i < TEST_FILES.length; ++i) {
            threads[i].join();
        }
        for (int i = 0; i < TEST_FILES.length; ++i) {
            contexts[i].verify();
        }
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            client.disconnect();
        } catch (Throwable t) {
        }
        try {
            bimServer.stop();
        } catch (Throwable t) {
        }
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) SRenderEnginePluginConfiguration(org.bimserver.interfaces.objects.SRenderEnginePluginConfiguration) BimServer(org.bimserver.BimServer) IOException(java.io.IOException) BimServerConfig(org.bimserver.BimServerConfig) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) IOException(java.io.IOException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) SPluginDescriptor(org.bimserver.interfaces.objects.SPluginDescriptor) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException)

Example 25 with SDeserializerPluginConfiguration

use of org.bimserver.interfaces.objects.SDeserializerPluginConfiguration in project BIMserver by opensourceBIM.

the class TestSimultaniousDownloadWithCaching method start.

private void start() {
    BimServerConfig config = new BimServerConfig();
    Path homeDir = Paths.get("home");
    try {
        if (Files.isDirectory(homeDir)) {
            PathUtils.removeDirectoryWithContent(homeDir);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    config.setClassPath(System.getProperty("java.class.path"));
    config.setHomeDir(homeDir);
    config.setPort(8080);
    config.setStartEmbeddedWebServer(true);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    final BimServer bimServer = new BimServer(config);
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
        }
    } catch (PluginException e2) {
        e2.printStackTrace();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (DatabaseInitException e) {
        e.printStackTrace();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    }
    try {
        final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
        ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
        SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
        final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
        serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
        settingsInterface.setCacheOutputFiles(true);
        settingsInterface.setGenerateGeometryOnCheckin(false);
        final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
        Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
        serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
        final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
        ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
        for (int i = 0; i < 20; i++) {
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
                        SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
                        Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
                        SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
                        if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
                            CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
                            try {
                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                c.writeToOutputStream(baos, null);
                                System.out.println(baos.size());
                            } catch (SerializerException e) {
                                e.printStackTrace();
                            }
                        } else {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            IOUtils.copy(downloadData.getFile().getInputStream(), baos);
                            System.out.println(baos.size());
                        }
                        serviceMap2.getServiceInterface().cleanupLongAction(download);
                    } catch (ServerException e) {
                        e.printStackTrace();
                    } catch (UserException e) {
                        e.printStackTrace();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (PublicInterfaceNotFoundException e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.HOURS);
        bimServer.stop();
    } catch (ServerException e1) {
        e1.printStackTrace();
    } catch (UserException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e2) {
        e2.printStackTrace();
    }
}
Also used : AuthInterface(org.bimserver.shared.interfaces.AuthInterface) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServiceMap(org.bimserver.webservices.ServiceMap) CacheStoringEmfSerializerDataSource(org.bimserver.plugins.serializers.CacheStoringEmfSerializerDataSource) FileNotFoundException(java.io.FileNotFoundException) DataHandler(javax.activation.DataHandler) BimServerConfig(org.bimserver.BimServerConfig) SProject(org.bimserver.interfaces.objects.SProject) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) FileDataSource(javax.activation.FileDataSource) UserException(org.bimserver.shared.exceptions.UserException) Path(java.nio.file.Path) ServerException(org.bimserver.shared.exceptions.ServerException) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) SDownloadResult(org.bimserver.interfaces.objects.SDownloadResult) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SerializerException(org.bimserver.plugins.serializers.SerializerException) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)45 SProject (org.bimserver.interfaces.objects.SProject)39 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)31 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)27 Test (org.junit.Test)21 IOException (java.io.IOException)19 URL (java.net.URL)19 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)18 UserException (org.bimserver.shared.exceptions.UserException)16 IfcModelInterface (org.bimserver.emf.IfcModelInterface)15 ServerException (org.bimserver.shared.exceptions.ServerException)15 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)12 Path (java.nio.file.Path)9 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 DatabaseSession (org.bimserver.database.DatabaseSession)8 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)7 ServiceException (org.bimserver.shared.exceptions.ServiceException)7 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)5 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)5 DeserializerPluginConfiguration (org.bimserver.models.store.DeserializerPluginConfiguration)5