Search in sources :

Example 1 with SDeserializerPluginConfiguration

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

the class BimServerImporter method start.

public void start() {
    try (BimServerClientFactory factory = new JsonBimServerClientFactory(bimServer.getMetaDataManager(), address)) {
        LOGGER.info("Importing...");
        remoteClient = factory.create(new UsernamePasswordAuthenticationInfo(username, password));
        final BimDatabase database = bimServer.getDatabase();
        DatabaseSession databaseSession = database.createSession();
        try {
            LOGGER.info("Users...");
            for (SUser user : remoteClient.getServiceInterface().getAllUsers()) {
                createUser(databaseSession, user.getOid());
            }
            LOGGER.info("Projects...");
            for (SProject project : remoteClient.getServiceInterface().getAllProjects(false, false)) {
                createProject(databaseSession, project.getOid());
            }
            LOGGER.info("Done");
            databaseSession.commit();
        } catch (BimserverDatabaseException e) {
            LOGGER.error("", e);
        } finally {
            databaseSession.close();
        }
        final BimServerClientInterface client = bimServer.getBimServerClientFactory().create(new UsernamePasswordAuthenticationInfo(username, password));
        // for (SRenderEnginePluginConfiguration renderEnginePluginConfiguration : client.getPluginInterface().getAllRenderEngines(true)) {
        // if (renderEnginePluginConfiguration.getName().equals("IFC Engine DLL")) {
        // client.getPluginInterface().setDefaultRenderEngine(renderEnginePluginConfiguration.getOid());
        // }
        // }
        Path incoming = Paths.get(path);
        final Map<GregorianCalendar, Key> comments = new TreeMap<>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
        for (SProject project : remoteClient.getServiceInterface().getAllProjects(false, false)) {
            for (SRevision revision : remoteClient.getServiceInterface().getAllRevisionsOfProject(project.getOid())) {
                GregorianCalendar gregorianCalendar = new GregorianCalendar();
                gregorianCalendar.setTime(revision.getDate());
                if (!revision.getComment().startsWith("generated for")) {
                    User user = users.get(revision.getUserId());
                    Path userFolder = incoming.resolve(user.getUsername());
                    boolean found = false;
                    for (Path file : PathUtils.list(userFolder)) {
                        if (file.getFileName().toString().endsWith(revision.getComment())) {
                            String dateStr = file.getFileName().toString().substring(0, 19);
                            Date parse = dateFormat.parse(dateStr);
                            GregorianCalendar fileDate = new GregorianCalendar();
                            fileDate.setTime(parse);
                            long millisDiff = Math.abs(fileDate.getTimeInMillis() - revision.getDate().getTime());
                            if (millisDiff > 1000 * 60 * 120) {
                                // 120 minutes
                                continue;
                            }
                            if (revision.getOid() == project.getLastRevisionId()) {
                                comments.put(gregorianCalendar, new Key(file, project.getOid(), revision.getComment(), revision.getDate(), revision.getUserId()));
                            }
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        LOGGER.info("Not found: " + revision.getComment());
                    }
                }
            }
        }
        ExecutorService executorService = new ThreadPoolExecutor(1, 1, 1, TimeUnit.DAYS, new ArrayBlockingQueue<Runnable>(1000));
        for (final GregorianCalendar gregorianCalendar : comments.keySet()) {
            executorService.submit(new Runnable() {

                @Override
                public void run() {
                    Key key = comments.get(gregorianCalendar);
                    LOGGER.info("Checking in: " + key.file.getFileName().toString() + " " + Formatters.bytesToString(key.file.toFile().length()));
                    Project sProject = projects.get(key.poid);
                    try {
                        SDeserializerPluginConfiguration desserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", sProject.getOid());
                        client.checkin(sProject.getOid(), key.comment, desserializer.getOid(), false, Flow.SYNC, key.file);
                        SProject updatedProject = client.getServiceInterface().getProjectByPoid(sProject.getOid());
                        DatabaseSession databaseSession = database.createSession();
                        try {
                            LOGGER.info("Done");
                            Project project = databaseSession.get(updatedProject.getOid(), OldQuery.getDefault());
                            Revision revision = project.getLastRevision();
                            User user = (User) databaseSession.get(users.get(key.userId).getOid(), OldQuery.getDefault());
                            for (Revision otherRevision : revision.getConcreteRevisions().get(0).getRevisions()) {
                                otherRevision.load();
                                otherRevision.setDate(key.date);
                                otherRevision.setComment(otherRevision.getComment().replace("Administrator", user.getName()));
                                databaseSession.store(otherRevision);
                            }
                            DateFormat m = new SimpleDateFormat("dd-MM-yyyy");
                            LOGGER.info("Setting date to " + m.format(key.date));
                            revision.setUser(user);
                            revision.setDate(key.date);
                            databaseSession.store(revision);
                            databaseSession.commit();
                        } catch (BimserverDatabaseException | ServiceException e) {
                            LOGGER.error("", e);
                        } finally {
                            databaseSession.close();
                        }
                    } catch (IOException | UserException | ServerException | PublicInterfaceNotFoundException e) {
                        LOGGER.error("", e);
                    }
                }
            });
        }
        executorService.shutdown();
    } catch (ServiceException e) {
        LOGGER.error("", e);
    } catch (ChannelConnectionException e) {
        LOGGER.error("", e);
    } catch (PublicInterfaceNotFoundException e) {
        LOGGER.error("", e);
    } catch (ParseException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (BimServerClientException e1) {
        LOGGER.error("", e1);
    } catch (Exception e2) {
        LOGGER.error("", e2);
    }
}
Also used : User(org.bimserver.models.store.User) SUser(org.bimserver.interfaces.objects.SUser) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DatabaseSession(org.bimserver.database.DatabaseSession) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SUser(org.bimserver.interfaces.objects.SUser) SProject(org.bimserver.interfaces.objects.SProject) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) Path(java.nio.file.Path) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) GregorianCalendar(java.util.GregorianCalendar) IOException(java.io.IOException) TreeMap(java.util.TreeMap) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) Date(java.util.Date) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) ParseException(java.text.ParseException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) SRevision(org.bimserver.interfaces.objects.SRevision) Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) Revision(org.bimserver.models.store.Revision) SRevision(org.bimserver.interfaces.objects.SRevision) ServiceException(org.bimserver.shared.exceptions.ServiceException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ParseException(java.text.ParseException) BimDatabase(org.bimserver.database.BimDatabase) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with SDeserializerPluginConfiguration

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

the class TestSetWrappedIntegerGeometry method test.

@Test
public void test() {
    try {
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkin(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/revit_quantities.ifc"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, false);
        long tid = lowLevelInterface.startTransaction(newProject.getOid());
        IfcPropertySingleValue ifcPropertySingleValue = model.getAll(IfcPropertySingleValue.class).iterator().next();
        bimServerClient.getLowLevelInterface().setWrappedLongAttribute(tid, ifcPropertySingleValue.getOid(), "NominalValue", "IfcInteger", 12345L);
        long roid = lowLevelInterface.commitTransaction(tid, "v2");
        IfcModelInterface newModel = bimServerClient.getModel(newProject, roid, true, false, true);
        SVector3f minBounds = newModel.getModelMetaData().getMinBounds();
        SVector3f maxBounds = newModel.getModelMetaData().getMaxBounds();
        org.junit.Assert.assertNotNull(minBounds);
        org.junit.Assert.assertNotNull(maxBounds);
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test2.ifc"));
        bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SVector3f(org.bimserver.interfaces.objects.SVector3f) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) URL(java.net.URL) Test(org.junit.Test)

Example 3 with SDeserializerPluginConfiguration

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

the class MultiCheckinAndDownload method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        long s = System.nanoTime();
        for (int i = 0; i < 3; i++) {
            // Create a new project
            SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
            // This is the file we will be checking in
            File ifcFile = new File("../TestData/data/AC11-FZK-Haus-IFC.ifc");
            // Find a deserializer to use
            SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
            // Checkin
            Long progressId = bimServerClient.getServiceInterface().checkin(newProject.getOid(), "test", deserializer.getOid(), ifcFile.length(), ifcFile.getName(), new DataHandler(new FileDataSource(ifcFile)), false, true);
            // Get the status
            SLongActionState longActionState = bimServerClient.getRegistry().getProgress(progressId);
            if (longActionState.getState() == SActionState.FINISHED) {
                // Find a serializer
                SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
                // Get the project details
                newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
                // Download the latest revision  (the one we just checked in)
                Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), true);
                SLongActionState downloadState = bimServerClient.getRegistry().getProgress(topicId);
                if (downloadState.getState() == SActionState.FINISHED) {
                    // Success
                    System.out.println("Success");
                }
            }
        }
        long e = System.nanoTime();
        System.out.println(((e - s) / 1000000) + " ms");
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) DataHandler(javax.activation.DataHandler) SProject(org.bimserver.interfaces.objects.SProject) FileDataSource(javax.activation.FileDataSource) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) File(java.io.File) Test(org.junit.Test)

Example 4 with SDeserializerPluginConfiguration

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

the class SingleCheckinAndDownload method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // When you use the channel for checkin/download calls, all data will have to be converted to the used channel's format, for example for JSON, binary data will be Base64 encoded, which will make things slower and larger
        // The alternative is to use the Servlets, those will also use compression where possible
        // Using the channel is slower
        boolean useChannel = false;
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Find a deserializer to use
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin
        Long progressId = -1L;
        // if (useChannel) {
        // progressId = bimServerClient.getServiceInterface().checkin(newProject.getOid(), "test", deserializer.getOid(), ifcFile.toFile().length(), ifcFile.getFileName().toString(), new DataHandler(new FileDataSource(ifcFile.toFile())), true, true);
        // } else {
        progressId = bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // }
        // Get the status
        SLongActionState longActionState = bimServerClient.getRegistry().getProgress(progressId);
        if (longActionState.getState() == SActionState.FINISHED) {
            // Find a serializer
            SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
            // Get the project details
            newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
            // Download the latest revision  (the one we just checked in)
            if (useChannel) {
                Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), true);
                SLongActionState downloadState = bimServerClient.getRegistry().getProgress(topicId);
                if (downloadState.getState() == SActionState.FINISHED) {
                    InputStream inputStream = bimServerClient.getServiceInterface().getDownloadData(topicId).getFile().getInputStream();
                    IOUtils.copy(inputStream, new ByteArrayOutputStream());
                    System.out.println("Success");
                }
            } else {
                // Note: sync: false
                Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), false);
                InputStream downloadData = bimServerClient.getDownloadData(topicId);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(downloadData, baos);
                System.out.println(baos.size() + " bytes downloaded");
            }
        } else {
            System.out.println(longActionState.getState());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) InputStream(java.io.InputStream) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 5 with SDeserializerPluginConfiguration

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

the class SingleCheckinAndDownloadSimplified method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // This is the file we will be checking in
        Path ifcFile = Paths.get("../TestData/data/AC11-FZK-Haus-IFC.ifc");
        // Find a deserializer to use
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin
        bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, ifcFile);
        // Find a serializer
        SSerializerPluginConfiguration colladaSerializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/collada");
        // Get the project details
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        // Download the latest revision  (the one we just checked in)
        // Note: sync: false
        Long topicIdId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), colladaSerializer.getOid(), false);
        InputStream downloadData = bimServerClient.getDownloadData(topicIdId);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(downloadData, baos);
        System.out.println(baos.size() + " bytes downloaded");
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) InputStream(java.io.InputStream) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

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