Search in sources :

Example 21 with PublicInterfaceNotFoundException

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

the class BimServerClient method authenticate.

public void authenticate() throws ServerException, UserException {
    try {
        AuthInterface authInterface = channel.get(AuthInterface.class);
        if (authenticationInfo instanceof UsernamePasswordAuthenticationInfo) {
            UsernamePasswordAuthenticationInfo usernamePasswordAuthenticationInfo = (UsernamePasswordAuthenticationInfo) authenticationInfo;
            setToken(authInterface.login(usernamePasswordAuthenticationInfo.getUsername(), usernamePasswordAuthenticationInfo.getPassword()));
        } else if (authenticationInfo instanceof AutologinAuthenticationInfo) {
            AutologinAuthenticationInfo autologinAuthenticationInfo = (AutologinAuthenticationInfo) authenticationInfo;
            setToken(autologinAuthenticationInfo.getAutologinCode());
        } else if (authenticationInfo instanceof TokenAuthentication) {
            TokenAuthentication tokenAuthentication = (TokenAuthentication) authenticationInfo;
            setToken(tokenAuthentication.getToken());
        } else if (authenticationInfo instanceof UserTokenAuthentication) {
            UserTokenAuthentication tokenAuthentication = (UserTokenAuthentication) authenticationInfo;
            setToken(authInterface.loginUserToken(tokenAuthentication.getToken()));
        } else if (authenticationInfo instanceof SystemAuthentication) {
        }
    } catch (PublicInterfaceNotFoundException e) {
        LOGGER.error("", e);
    }
}
Also used : AuthInterface(org.bimserver.shared.interfaces.AuthInterface) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) UserTokenAuthentication(org.bimserver.shared.UserTokenAuthentication) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) AutologinAuthenticationInfo(org.bimserver.shared.AutologinAuthenticationInfo) TokenAuthentication(org.bimserver.shared.TokenAuthentication) UserTokenAuthentication(org.bimserver.shared.UserTokenAuthentication) SystemAuthentication(org.bimserver.shared.SystemAuthentication)

Example 22 with PublicInterfaceNotFoundException

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

the class BimServerClient method download.

public void download(long roid, long serializerOid, OutputStream outputStream) throws BimServerClientException {
    try {
        Long topicId = getServiceInterface().download(Collections.singleton(roid), DefaultQueries.allAsString(), serializerOid, false);
        SLongActionState progress = getNotificationRegistryInterface().getProgress(topicId);
        if (progress != null && progress.getState() == SActionState.AS_ERROR) {
            throw new BimServerClientException(Joiner.on(", ").join(progress.getErrors()));
        } else {
            InputStream inputStream = getDownloadData(topicId);
            try {
                IOUtils.copy(inputStream, outputStream);
                getServiceInterface().cleanupLongAction(topicId);
            } finally {
                inputStream.close();
            }
        }
    } catch (ServerException e) {
        LOGGER.error("", e);
    } catch (UserException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (PublicInterfaceNotFoundException e) {
        LOGGER.error("", e);
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 23 with PublicInterfaceNotFoundException

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

the class Channel method checkin.

public long checkin(String baseAddress, String token, long poid, String comment, long deserializerOid, boolean merge, Flow flow, long fileSize, String filename, InputStream inputStream) throws ServerException, UserException {
    String address = baseAddress + "/upload";
    HttpPost httppost = new HttpPost(address);
    try {
        Long 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 = MultipartEntityBuilder.create();
        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("" + (flow == Flow.SYNC), 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) {
            JsonParser jsonParser = new JsonParser();
            InputStreamReader in = new InputStreamReader(httpResponse.getEntity().getContent());
            try {
                JsonElement result = jsonParser.parse(new JsonReader(in));
                if (result instanceof JsonObject) {
                    JsonObject jsonObject = (JsonObject) result;
                    if (jsonObject.has("exception")) {
                        JsonObject exceptionJson = jsonObject.get("exception").getAsJsonObject();
                        String exceptionType = exceptionJson.get("__type").getAsString();
                        String message = exceptionJson.has("message") ? exceptionJson.get("message").getAsString() : "unknown";
                        if (exceptionType.equals(UserException.class.getSimpleName())) {
                            throw new UserException(message);
                        } else if (exceptionType.equals(ServerException.class.getSimpleName())) {
                            throw new ServerException(message);
                        }
                    } else {
                        if (jsonObject.has("topicId")) {
                            return jsonObject.get("topicId").getAsLong();
                        } else {
                            throw new ServerException("No topicId found in response: " + jsonObject.toString());
                        }
                    }
                }
            } finally {
                in.close();
            }
        }
    } catch (ClientProtocolException e) {
        throw new ServerException(e);
    } catch (IOException e) {
        throw new ServerException(e);
    } catch (PublicInterfaceNotFoundException e) {
        throw new ServerException(e);
    } finally {
        httppost.releaseConnection();
    }
    return -1;
}
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) DeflaterInputStream(java.util.zip.DeflaterInputStream) HttpResponse(org.apache.http.HttpResponse) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) StringBody(org.apache.http.entity.mime.content.StringBody) JsonElement(com.google.gson.JsonElement) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) InputStreamBody(org.apache.http.entity.mime.content.InputStreamBody) JsonReader(com.google.gson.stream.JsonReader) UserException(org.bimserver.shared.exceptions.UserException) JsonParser(com.google.gson.JsonParser)

Example 24 with PublicInterfaceNotFoundException

use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException 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 25 with PublicInterfaceNotFoundException

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

the class TestChangeDescription method start.

private void start() {
    BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
    try {
        SProject project = client.getServiceInterface().getProjectsByName("dfgfgdf").get(0);
        IfcModelInterface model = client.getModel(project, project.getLastRevisionId(), false, true);
        for (IfcWall wall : model.getAllWithSubTypes(IfcWall.class)) {
            wall.setDescription(wall.getDescription() + " Changed");
        }
        model.commit("test");
    } catch (UserException e) {
        e.printStackTrace();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ServerException(org.bimserver.shared.exceptions.ServerException) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Aggregations

PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)38 SProject (org.bimserver.interfaces.objects.SProject)22 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)20 ServiceException (org.bimserver.shared.exceptions.ServiceException)20 IOException (java.io.IOException)19 ServerException (org.bimserver.shared.exceptions.ServerException)18 UserException (org.bimserver.shared.exceptions.UserException)18 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)15 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)12 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)10 Path (java.nio.file.Path)9 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)8 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)7 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)6 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3