Search in sources :

Example 16 with InternalServicePluginConfiguration

use of org.bimserver.models.store.InternalServicePluginConfiguration 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)

Aggregations

InternalServicePluginConfiguration (org.bimserver.models.store.InternalServicePluginConfiguration)16 DatabaseSession (org.bimserver.database.DatabaseSession)12 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)10 ServerException (org.bimserver.shared.exceptions.ServerException)8 SInternalServicePluginConfiguration (org.bimserver.interfaces.objects.SInternalServicePluginConfiguration)7 User (org.bimserver.models.store.User)7 UserException (org.bimserver.shared.exceptions.UserException)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 UserSettings (org.bimserver.models.store.UserSettings)5 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 AttributeCondition (org.bimserver.database.query.conditions.AttributeCondition)3 Condition (org.bimserver.database.query.conditions.Condition)3 StringLiteral (org.bimserver.database.query.literals.StringLiteral)3 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)2 SObjectType (org.bimserver.interfaces.objects.SObjectType)2 SProfileDescriptor (org.bimserver.interfaces.objects.SProfileDescriptor)2 ObjectType (org.bimserver.models.store.ObjectType)2 PluginConfiguration (org.bimserver.models.store.PluginConfiguration)2 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)2