Search in sources :

Example 6 with JsonBimServerClientFactory

use of org.bimserver.client.json.JsonBimServerClientFactory in project BIMserver by opensourceBIM.

the class ServiceImpl method getAllPrivateProfiles.

@Override
public List<SProfileDescriptor> getAllPrivateProfiles(String notificationsUrl, String serviceIdentifier) throws ServerException, UserException {
    if (notificationsUrl == null) {
        throw new UserException("Missing notificationsUrl");
    }
    requireRealUserAuthentication();
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        try (BimServerClientFactory factory = new JsonBimServerClientFactory(notificationsUrl, getBimServer().getServicesMap(), getBimServer().getJsonSocketReflectorFactory(), getBimServer().getReflectorFactory(), getBimServer().getMetaDataManager())) {
            BimServerClientInterface client = factory.create();
            OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_ApiUrl(), notificationsUrl);
            User user = session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
            for (OAuthAuthorizationCode oAuthAuthorizationCode : user.getOAuthAuthorizationCodes()) {
                if (oAuthAuthorizationCode.getOauthServer() == oAuthServer) {
                    return client.getRemoteServiceInterface().getPrivateProfiles(serviceIdentifier, oAuthAuthorizationCode.getCode());
                }
            }
            return null;
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException) OAuthServer(org.bimserver.models.store.OAuthServer) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) OAuthAuthorizationCode(org.bimserver.models.store.OAuthAuthorizationCode) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Example 7 with JsonBimServerClientFactory

use of org.bimserver.client.json.JsonBimServerClientFactory in project BIMserver by opensourceBIM.

the class ServiceImpl method getServiceDescriptor.

@Override
public SServiceDescriptor getServiceDescriptor(String baseUrl, String serviceIdentifier) throws ServerException, UserException {
    requireRealUserAuthentication();
    try {
        try (BimServerClientFactory factory = new JsonBimServerClientFactory(baseUrl, getBimServer().getServicesMap(), getBimServer().getJsonSocketReflectorFactory(), getBimServer().getReflectorFactory(), getBimServer().getMetaDataManager())) {
            BimServerClientInterface client = factory.create();
            SServiceDescriptor service = client.getRemoteServiceInterface().getService(serviceIdentifier);
            if (service == null) {
                throw new UserException("No service found with identifier " + serviceIdentifier);
            }
            service.setUrl(baseUrl);
            return service;
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException) SServiceDescriptor(org.bimserver.interfaces.objects.SServiceDescriptor) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Example 8 with JsonBimServerClientFactory

use of org.bimserver.client.json.JsonBimServerClientFactory in project BIMserver by opensourceBIM.

the class TestBigFilesRemote method start.

private void start(String[] args) {
    String address = args[0];
    String username = args[1];
    String password = args[2];
    String basepath = args[3];
    System.out.println("Address: " + address);
    System.out.println("Username: " + username);
    System.out.println("Password: " + password);
    System.out.println("Basepath: " + basepath);
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory(null, address)) {
        BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo(args[1], args[2]));
        String[] fileNames = new String[] { "4NC Whole Model.ifc", "1006 General withIFC_exportLayerCombos.ifc", "12001_17 MOS_AC17SpecialBigVersion.ifc", "12510_MASTER_Drofus_Test.ifc", "BondBryan10-134 (06) Proposed Site-1.ifc", "HLM_39090_12259 University of Sheffield NEB  [PR-BIM-01-bhelberg].ifc" };
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
        for (String fileName : fileNames) {
            String projectName = fileName.substring(0, fileName.lastIndexOf(".ifc"));
            List<SProject> projectsByName = client.getServiceInterface().getProjectsByName(projectName);
            SProject project = null;
            if (projectsByName.size() == 1) {
                project = projectsByName.get(0);
            } else {
                System.out.println("Creating project " + fileName);
                project = client.getServiceInterface().addProject(projectName, "ifc2x3tc1");
            }
            SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
            System.out.println(dateFormat.format(new Date()));
            SDatabaseInformation databaseInformation = client.getAdminInterface().getDatabaseInformation();
            System.out.println("Database size: " + Formatters.bytesToString(databaseInformation.getDatabaseSizeInBytes()) + " (" + databaseInformation.getDatabaseSizeInBytes() + ")");
            SJavaInfo javaInfo = client.getAdminInterface().getJavaInfo();
            System.out.println("Used: " + Formatters.bytesToString(javaInfo.getHeapUsed()) + ", Free: " + Formatters.bytesToString(javaInfo.getHeapFree()) + ", Max: " + Formatters.bytesToString(javaInfo.getHeapMax()) + ", Total: " + Formatters.bytesToString(javaInfo.getHeapTotal()));
            String downloadUrl = basepath + UrlEscapers.urlPathSegmentEscaper().escape(fileName);
            System.out.println("Download URL: " + downloadUrl);
            client.getServiceInterface().checkinFromUrl(project.getOid(), fileName, deserializer.getOid(), fileName, downloadUrl, false, true);
            System.out.println("Done checking in " + fileName);
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ChannelConnectionException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SDatabaseInformation(org.bimserver.interfaces.objects.SDatabaseInformation) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) BimServerClient(org.bimserver.client.BimServerClient) Date(java.util.Date) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) ServiceException(org.bimserver.shared.exceptions.ServiceException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SJavaInfo(org.bimserver.interfaces.objects.SJavaInfo) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with JsonBimServerClientFactory

use of org.bimserver.client.json.JsonBimServerClientFactory in project BIMserver by opensourceBIM.

the class TestMultiple method main.

public static void main(String[] args) throws InterruptedException {
    try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 1, TimeUnit.DAYS, new ArrayBlockingQueue<>(2));
        for (int i = 0; i < 2; i++) {
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        SProject project = client.getServiceInterface().addProject("P" + new Random().nextInt(), "ifc2x3tc1");
                        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
                        client.checkin(project.getOid(), "Test", deserializer.getOid(), false, Flow.ASYNC, Paths.get("C:\\Git\\TestFiles\\TestData\\data\\HITOS_070308.ifc"));
                    } catch (ServerException e) {
                        e.printStackTrace();
                    } catch (UserException e) {
                        e.printStackTrace();
                    } catch (PublicInterfaceNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.HOURS);
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ChannelConnectionException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) Random(java.util.Random) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) UserException(org.bimserver.shared.exceptions.UserException)

Example 10 with JsonBimServerClientFactory

use of org.bimserver.client.json.JsonBimServerClientFactory in project BIMserver by opensourceBIM.

the class TestNewQueryViaClient method start.

private void start() {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        String projectName = "Test " + new Random().nextInt();
        SProject project = client.getServiceInterface().addProject(projectName, "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        client.checkin(project.getOid(), "Test Model", deserializer.getOid(), false, Flow.SYNC, Paths.get("C:/Git/TestFiles/TestData/data/AC11-FZK-Haus-IFC.ifc"));
        project = client.getServiceInterface().getProjectByPoid(project.getOid());
        System.out.println(project.getName());
        ClientIfcModel model = client.getModel(project, project.getLastRevisionId(), false, false);
        Query query = new Query(model.getPackageMetaData());
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(Ifc2x3tc1Package.eINSTANCE.getIfcWall(), true);
        for (IfcWall ifcWall : model.getAllWithSubTypes(IfcWall.class)) {
            System.out.println(ifcWall.getGlobalId());
        }
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ChannelConnectionException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) Query(org.bimserver.database.queries.om.Query) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) QueryPart(org.bimserver.database.queries.om.QueryPart) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) BimServerClient(org.bimserver.client.BimServerClient) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) Random(java.util.Random) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Aggregations

JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)12 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)9 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)8 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)8 ServiceException (org.bimserver.shared.exceptions.ServiceException)8 IOException (java.io.IOException)7 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)7 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)7 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)7 SProject (org.bimserver.interfaces.objects.SProject)6 ServerException (org.bimserver.shared.exceptions.ServerException)6 UserException (org.bimserver.shared.exceptions.UserException)6 Path (java.nio.file.Path)5 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 BimServerClient (org.bimserver.client.BimServerClient)3 DatabaseSession (org.bimserver.database.DatabaseSession)3 MetaDataManager (org.bimserver.emf.MetaDataManager)3 SUser (org.bimserver.interfaces.objects.SUser)3 PluginManager (org.bimserver.plugins.PluginManager)3