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;
}
Aggregations