Search in sources :

Example 1 with SLongCheckinActionState

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

the class TestGetGeometry2 method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
            SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {

                @Override
                public void progress(String title, int progress) {
                    System.out.println(title + ": " + progress);
                }
            });
            ClientIfcModel model = client.getModel(project, actionState.getRoid(), false, false, true);
            for (IfcProduct product : model.getAllWithSubTypes(IfcProduct.class)) {
                GeometryInfo geometry = product.getGeometry();
                if (geometry != null) {
                    System.out.println(product.getGeometry().getData().getNrVertices());
                    System.out.println(product.getGeometry().getData().getVertices().getData().length);
                }
            }
        }
    }
    Thread.sleep(1000);
}
Also used : Path(java.nio.file.Path) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) Test(org.junit.Test)

Example 2 with SLongCheckinActionState

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

the class ServiceImpl method checkinInternal.

private SLongCheckinActionState checkinInternal(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, InputStream originalInputStream, Boolean merge, Boolean sync, final DatabaseSession readOnlySession, String username, String userUsername, Project project, Path file, long newServiceId) throws BimserverDatabaseException, IOException, DeserializeException, CannotBeScheduledException, ServiceException {
    DeserializerPluginConfiguration deserializerPluginConfiguration = readOnlySession.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
    if (deserializerPluginConfiguration == null) {
        throw new UserException("Deserializer with oid " + deserializerOid + " not found");
    } else {
        PluginBundleVersion pluginBundleVersion = deserializerPluginConfiguration.getPluginDescriptor().getPluginBundleVersion();
        Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
        if (plugin != null) {
            if (plugin instanceof DeserializerPlugin) {
                DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
                Deserializer deserializer = deserializerPlugin.createDeserializer(getBimServer().getPluginSettingsCache().getPluginSettings(deserializerOid));
                OutputStream outputStream = Files.newOutputStream(file);
                InputStream inputStream = new MultiplexingInputStream(originalInputStream, outputStream);
                deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
                IfcModelInterface model = null;
                try {
                    model = deserializer.read(inputStream, fileName, fileSize, null);
                } finally {
                    inputStream.close();
                }
                CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge, newServiceId, topicId);
                LongCheckinAction longAction = new LongCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
                getBimServer().getLongActionManager().start(longAction);
                if (sync) {
                    longAction.waitForCompletion();
                    clearCheckinInProgress(poid);
                }
                ProgressTopic progressTopic = getBimServer().getNotificationsManager().getProgressTopic(topicId);
                return (SLongCheckinActionState) getBimServer().getSConverter().convertToSObject(progressTopic.getLastProgress());
            } else if (plugin instanceof StreamingDeserializerPlugin) {
                StreamingDeserializerPlugin streaminDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
                StreamingDeserializer streamingDeserializer = streaminDeserializerPlugin.createDeserializer(getBimServer().getPluginSettingsCache().getPluginSettings(deserializerPluginConfiguration.getOid()));
                streamingDeserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
                RestartableInputStream restartableInputStream = new RestartableInputStream(originalInputStream, file);
                StreamingCheckinDatabaseAction checkinDatabaseAction = new StreamingCheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), comment, fileName, restartableInputStream, streamingDeserializer, fileSize, newServiceId, pluginBundleVersion, topicId);
                LongStreamingCheckinAction longAction = new LongStreamingCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
                getBimServer().getLongActionManager().start(longAction);
                ProgressTopic progressTopic = null;
                if (sync) {
                    longAction.waitForCompletion();
                    progressTopic = longAction.getProgressTopic();
                    clearCheckinInProgress(poid);
                    SLongCheckinActionState convertToSObject = (SLongCheckinActionState) getBimServer().getSConverter().convertToSObject(progressTopic.getLastProgress());
                    getBimServer().getLongActionManager().remove(progressTopic.getKey().getId());
                    return convertToSObject;
                } else {
                    return (SLongCheckinActionState) getBimServer().getSConverter().convertToSObject(longAction.getState());
                }
            } else {
                throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
            }
        } else {
            throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
        }
    }
}
Also used : MultiplexingInputStream(org.bimserver.utils.MultiplexingInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiplexingInputStream(org.bimserver.utils.MultiplexingInputStream) InputStream(java.io.InputStream) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) CheckinDatabaseAction(org.bimserver.database.actions.CheckinDatabaseAction) StreamingCheckinDatabaseAction(org.bimserver.database.actions.StreamingCheckinDatabaseAction) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DeserializerPluginConfiguration(org.bimserver.models.store.DeserializerPluginConfiguration) StreamingDeserializer(org.bimserver.plugins.deserializers.StreamingDeserializer) ProgressTopic(org.bimserver.notifications.ProgressTopic) Deserializer(org.bimserver.plugins.deserializers.Deserializer) StreamingDeserializer(org.bimserver.plugins.deserializers.StreamingDeserializer) LongStreamingCheckinAction(org.bimserver.longaction.LongStreamingCheckinAction) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) LongCheckinAction(org.bimserver.longaction.LongCheckinAction) UserException(org.bimserver.shared.exceptions.UserException) PluginBundleVersion(org.bimserver.models.store.PluginBundleVersion) StreamingCheckinDatabaseAction(org.bimserver.database.actions.StreamingCheckinDatabaseAction) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 3 with SLongCheckinActionState

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

the class Channel method checkinSync.

public SLongCheckinActionState checkinSync(String baseAddress, String token, long poid, String comment, long deserializerOid, boolean merge, long fileSize, String filename, InputStream inputStream, Long topicId) throws ServerException, UserException {
    String address = baseAddress + "/upload";
    HttpPost httppost = new HttpPost(address);
    try {
        if (topicId == null) {
            topicId = getServiceInterface().initiateCheckin(poid, deserializerOid);
        }
        // TODO find some GzipInputStream variant that _compresses_ instead
        // of _decompresses_ using deflate for now
        InputStreamBody data = new InputStreamBody(new DeflaterInputStream(inputStream), filename);
        MultipartEntityBuilder multipartEntityBuilder = createMultiPart();
        multipartEntityBuilder.addPart("topicId", new StringBody("" + topicId, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("token", new StringBody(token, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("deserializerOid", new StringBody("" + deserializerOid, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("merge", new StringBody("" + merge, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("poid", new StringBody("" + poid, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("comment", new StringBody("" + comment, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("sync", new StringBody("" + true, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("compression", new StringBody("deflate", ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("data", data);
        httppost.setEntity(multipartEntityBuilder.build());
        HttpResponse httpResponse = closeableHttpClient.execute(httppost);
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            ObjectMapper objectMapper = new ObjectMapper();
            InputStreamReader in = new InputStreamReader(httpResponse.getEntity().getContent());
            try {
                ObjectNode result = objectMapper.readValue(in, ObjectNode.class);
                if (result.has("exception")) {
                    ObjectNode exceptionJson = (ObjectNode) result.get("exception");
                    String exceptionType = exceptionJson.get("__type").asText();
                    String message = exceptionJson.has("message") ? exceptionJson.get("message").asText() : "unknown";
                    if (exceptionType.equals(UserException.class.getSimpleName())) {
                        throw new UserException(message);
                    } else if (exceptionType.equals(ServerException.class.getSimpleName())) {
                        throw new ServerException(message);
                    }
                } else {
                    SServicesMap sServicesMap = getSServicesMap();
                    try {
                        return (SLongCheckinActionState) getJsonConverter().fromJson(sServicesMap.getSType("SLongCheckinState"), null, result);
                    } catch (ConvertException e) {
                        throw new ServerException(e);
                    }
                }
            } finally {
                in.close();
            }
        } else {
            throw new ServerException("HTTP Status Code " + httpResponse.getStatusLine().getStatusCode() + " " + httpResponse.getStatusLine().getReasonPhrase());
        }
    } catch (ClientProtocolException e) {
        throw new ServerException(e);
    } catch (IOException e) {
        throw new ServerException(e);
    } catch (PublicInterfaceNotFoundException e) {
        throw new ServerException(e);
    } catch (Exception e) {
        throw new ServerException(e);
    } finally {
        httppost.releaseConnection();
    }
    throw new ServerException("Null result");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) ServerException(org.bimserver.shared.exceptions.ServerException) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConvertException(org.bimserver.shared.json.ConvertException) DeflaterInputStream(java.util.zip.DeflaterInputStream) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) ConvertException(org.bimserver.shared.json.ConvertException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) ClientProtocolException(org.apache.http.client.ClientProtocolException) SServicesMap(org.bimserver.shared.meta.SServicesMap) StringBody(org.apache.http.entity.mime.content.StringBody) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) InputStreamBody(org.apache.http.entity.mime.content.InputStreamBody) UserException(org.bimserver.shared.exceptions.UserException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with SLongCheckinActionState

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

the class TestGetGeometry method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
            SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> System.out.println(title + ": " + progress));
            PackageMetaData packageMetaData = client.getMetaDataManager().getPackageMetaData("ifc2x3tc1");
            GeometryTargetImpl geometryTargetImpl = new GeometryTargetImpl(packageMetaData);
            GeometryLoader geometryLoader = new GeometryLoader(client, packageMetaData, geometryTargetImpl);
            Set<Long> oids = new HashSet<>();
            // Only to gather oids
            ClientIfcModel model = client.getModel(project, actionState.getRoid(), true, false, false);
            for (IfcWall ifcWall : model.getAllWithSubTypes(IfcWall.class)) {
                oids.add(ifcWall.getOid());
            }
            geometryLoader.loadProducts(actionState.getRoid(), oids);
            System.out.println(geometryTargetImpl);
            Set<Long> geometryDataOids = new HashSet<>();
            for (GeometryInfo geometryInfo : geometryTargetImpl.getAllGeometryInfo()) {
                GeometryData geometryData = geometryInfo.getData();
                System.out.println(geometryInfo.getPrimitiveCount());
                System.out.println(geometryData.getNrIndices());
                geometryDataOids.add(geometryData.getOid());
            }
            geometryTargetImpl = new GeometryTargetImpl(packageMetaData);
            geometryLoader = new GeometryLoader(client, packageMetaData, geometryTargetImpl);
            geometryLoader.loadGeometryData(actionState.getRoid(), geometryDataOids);
            System.out.println(geometryTargetImpl);
        }
    }
    Thread.sleep(1000);
}
Also used : Path(java.nio.file.Path) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) GeometryTargetImpl(org.bimserver.client.GeometryTargetImpl) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) PackageMetaData(org.bimserver.emf.PackageMetaData) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) GeometryData(org.bimserver.models.geometry.GeometryData) SProject(org.bimserver.interfaces.objects.SProject) GeometryLoader(org.bimserver.client.GeometryLoader) BimServerClient(org.bimserver.client.BimServerClient) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SLongCheckinActionState

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

the class TestIfc4TwoDimensional method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc4");
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            Path path = Paths.get("../../TestFiles/TestData/data/ifc4add2tc1/tessellation-with-individual-colors.ifc");
            SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> System.out.println(title + ": " + progress));
            ClientIfcModel model = client.getModel(project, actionState.getRoid(), true, false);
            List<IfcColourRgbList> colourRgbLists = model.getAll(IfcColourRgbList.class);
            Assert.assertFalse(colourRgbLists.isEmpty());
            for (IfcColourRgbList colourRgbList : colourRgbLists) {
                Assert.assertEquals(3, colourRgbList.getColourList().size());
                for (ListOfIfcNormalisedRatioMeasure rgbValues : colourRgbList.getColourList()) {
                    Assert.assertEquals(3, rgbValues.getList().size());
                    for (IfcNormalisedRatioMeasure ifcNormalisedRatioMeasure : rgbValues.getList()) {
                        Assert.assertNotNull(ifcNormalisedRatioMeasure);
                    }
                }
            }
        }
        Thread.sleep(500);
    }
}
Also used : Path(java.nio.file.Path) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) SProject(org.bimserver.interfaces.objects.SProject) ListOfIfcNormalisedRatioMeasure(org.bimserver.models.ifc4.ListOfIfcNormalisedRatioMeasure) IfcNormalisedRatioMeasure(org.bimserver.models.ifc4.IfcNormalisedRatioMeasure) BimServerClient(org.bimserver.client.BimServerClient) ListOfIfcNormalisedRatioMeasure(org.bimserver.models.ifc4.ListOfIfcNormalisedRatioMeasure) IfcColourRgbList(org.bimserver.models.ifc4.IfcColourRgbList) Test(org.junit.Test)

Aggregations

SLongCheckinActionState (org.bimserver.interfaces.objects.SLongCheckinActionState)19 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)14 SProject (org.bimserver.interfaces.objects.SProject)14 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)11 Test (org.junit.Test)11 Path (java.nio.file.Path)10 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)10 BimServerClient (org.bimserver.client.BimServerClient)9 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 ClientIfcModel (org.bimserver.client.ClientIfcModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CheckinProgressHandler (org.bimserver.plugins.services.CheckinProgressHandler)5 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 SLongActionState (org.bimserver.interfaces.objects.SLongActionState)3 UserException (org.bimserver.shared.exceptions.UserException)3 URL (java.net.URL)2 IfcModelInterface (org.bimserver.emf.IfcModelInterface)2