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