Search in sources :

Example 51 with BimServerClientInterface

use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.

the class TestContainedInStructure method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the service interface
        bimServerClient.getSettingsInterface().setGenerateGeometryOnCheckin(false);
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Get the appropriate deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin the file
        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"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAllWithSubTypes(IfcFurnishingElement.class)) {
            System.out.println(ifcFurnishingElement);
            for (IfcRelContainedInSpatialStructure ifcRelContainedInSpatialStructure : ifcFurnishingElement.getContainedInStructure()) {
                System.out.println(ifcRelContainedInSpatialStructure.getRelatingStructure());
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 52 with BimServerClientInterface

use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.

the class TestCreateGuid 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");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        IfcFurnishingElement furnishing = model.create(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement());
        furnishing.setGlobalId("0uyjn9Jan3nRq36Uj6gwws");
        long roid = model.commit("Initial model");
        IfcModelInterface newModel = bimServerClient.getModel(newProject, roid, true, false);
        List<IfcFurnishingElement> furnishingElements = newModel.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement());
        assertTrue("There must be 1 furnishing element, not " + furnishingElements.size(), furnishingElements.size() == 1);
        IfcFurnishingElement newF = furnishingElements.get(0);
        assertTrue("GUID must be 0uyjn9Jan3nRq36Uj6gwws", newF.getGlobalId().equals("0uyjn9Jan3nRq36Uj6gwws"));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

Example 53 with BimServerClientInterface

use of org.bimserver.plugins.services.BimServerClientInterface in project BIMserver by opensourceBIM.

the class InternalServicesManager method getBimServerClient.

private P getBimServerClient(String serviceIdentifier, String profileIdentifier, String apiUrl, String token) {
    ServiceMapInterface serviceMapInterface = new ServiceMap(bimServer, null, AccessMethod.JSON);
    serviceMapInterface.add(RemoteServiceInterface.class, internalRemoteServiceInterfaces.get(serviceIdentifier));
    P p = new P();
    final InternalChannel internalChannel = new InternalChannel(bimServer.getServiceFactory(), bimServer.getServicesMap());
    try {
        internalChannel.connect(new SimpleTokenHolder());
    } catch (ChannelConnectionException e) {
        LOGGER.error("", e);
    }
    try {
        DatabaseSession session = bimServer.getDatabase().createSession();
        try {
            long profileId = Long.parseLong(profileIdentifier);
            EClass eClassForOid = session.getEClassForOid(profileId);
            InternalServicePluginConfiguration internalServicePluginConfiguration = null;
            if (eClassForOid == StorePackage.eINSTANCE.getInternalServicePluginConfiguration()) {
                internalServicePluginConfiguration = session.get(profileId, OldQuery.getDefault());
            } else if (eClassForOid == StorePackage.eINSTANCE.getService()) {
                Service service = session.get(profileId, OldQuery.getDefault());
                internalServicePluginConfiguration = service.getInternalService();
            } else {
                throw new RuntimeException("Oid is neither an InternalServicePluginConfiguration nor a Service");
            }
            final SObjectType settings = bimServer.getSConverter().convertToSObject(internalServicePluginConfiguration.getSettings());
            BimServerClientInterface bimServerClient = null;
            BimServerClientFactory factory = null;
            if (apiUrl == null) {
                factory = bimServer.getBimServerClientFactory();
            } else {
                if (factories.containsKey(apiUrl)) {
                    factory = factories.get(apiUrl);
                } else {
                    factory = new JsonBimServerClientFactory(apiUrl, bimServer.getServicesMap(), new JsonSocketReflectorFactory(bimServer.getServicesMap()), bimServer.getReflectorFactory(), bimServer.getMetaDataManager());
                    factories.put(apiUrl, factory);
                }
            }
            bimServerClient = factory.create(new TokenAuthentication(token));
            p.client = bimServerClient;
            p.settings = settings;
            return p;
        } catch (BimserverDatabaseException e) {
            LOGGER.error("", e);
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } catch (ChannelConnectionException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
    } finally {
    }
    return null;
}
Also used : SObjectType(org.bimserver.interfaces.objects.SObjectType) ServiceMap(org.bimserver.webservices.ServiceMap) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) DatabaseSession(org.bimserver.database.DatabaseSession) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) Service(org.bimserver.models.store.Service) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) ServiceMapInterface(org.bimserver.shared.ServiceMapInterface) JsonSocketReflectorFactory(org.bimserver.client.json.JsonSocketReflectorFactory) ServiceException(org.bimserver.shared.exceptions.ServiceException) SimpleTokenHolder(org.bimserver.client.SimpleTokenHolder) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) TokenAuthentication(org.bimserver.shared.TokenAuthentication)

Example 54 with BimServerClientInterface

use of org.bimserver.plugins.services.BimServerClientInterface 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 55 with BimServerClientInterface

use of org.bimserver.plugins.services.BimServerClientInterface 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)

Aggregations

BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)66 SProject (org.bimserver.interfaces.objects.SProject)57 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)46 Test (org.junit.Test)40 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)31 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)23 IfcModelInterface (org.bimserver.emf.IfcModelInterface)20 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)20 URL (java.net.URL)19 LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)19 IOException (java.io.IOException)16 ServiceException (org.bimserver.shared.exceptions.ServiceException)15 UserException (org.bimserver.shared.exceptions.UserException)13 ServerException (org.bimserver.shared.exceptions.ServerException)11 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)10 Path (java.nio.file.Path)8 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)7 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)7 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)6 File (java.io.File)4