Search in sources :

Example 41 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 {
            try (InputStream inputStream = getDownloadData(topicId)) {
                IOUtils.copy(inputStream, outputStream);
                getServiceInterface().cleanupLongAction(topicId);
            }
        }
    } 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) 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 42 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 43 with PublicInterfaceNotFoundException

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

the class Channel method bulkCheckin.

public void bulkCheckin(String baseAddress, String token, long poid, String comment, Path file) throws UserException, ServerException {
    String address = baseAddress + "/bulkupload";
    HttpPost httppost = new HttpPost(address);
    try (InputStream inputStream = Files.newInputStream(file)) {
        InputStreamBody data = new InputStreamBody(inputStream, file.getFileName().toString());
        MultipartEntityBuilder multipartEntityBuilder = createMultiPart();
        multipartEntityBuilder.addPart("token", new StringBody(token, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("poid", new StringBody("" + poid, ContentType.DEFAULT_TEXT));
        multipartEntityBuilder.addPart("comment", new StringBody("" + comment, 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);
                    }
                }
            } 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();
    }
}
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) DeflaterInputStream(java.util.zip.DeflaterInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) 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 44 with PublicInterfaceNotFoundException

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

the class Channel method checkinAsync.

public long checkinAsync(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 {
        // 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("" + false, 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 {
                    if (result.has("topicId")) {
                        return result.get("topicId").asLong();
                    } else {
                        throw new ServerException("No topicId found in response: " + result.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) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeflaterInputStream(java.util.zip.DeflaterInputStream) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) 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 45 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);
        SProject project = client.getServiceInterface().addProject("t2es035442t23", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "initial", deserializerForExtension.getOid(), false, Paths.get("../../TestFiles/TestData/data/AC11-FZK-Haus-IFC.ifc"));
        SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("GEOMETRY_GENERATION_REPORT_JSON_1_1");
        SExtendedData extendedData = new SExtendedData();
        extendedData.setFileId(fileId);
        extendedData.setTitle("test3");
        extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
        client.getServiceInterface().addExtendedDataToRevision(checkinSync.getRoid(), 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) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) 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)

Aggregations

PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)46 IOException (java.io.IOException)27 SProject (org.bimserver.interfaces.objects.SProject)24 ServerException (org.bimserver.shared.exceptions.ServerException)24 UserException (org.bimserver.shared.exceptions.UserException)24 ServiceException (org.bimserver.shared.exceptions.ServiceException)23 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)22 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)15 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)14 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)10 Path (java.nio.file.Path)9 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)8 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)8 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)7 InputStream (java.io.InputStream)6 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)6 InputStreamReader (java.io.InputStreamReader)4 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3