use of org.bimserver.shared.BimServerClientFactory in project BIMserver by opensourceBIM.
the class BimServerImporter method start.
public void start() {
try (BimServerClientFactory factory = new JsonBimServerClientFactory(bimServer.getMetaDataManager(), address)) {
LOGGER.info("Importing...");
remoteClient = factory.create(new UsernamePasswordAuthenticationInfo(username, password));
final BimDatabase database = bimServer.getDatabase();
DatabaseSession databaseSession = database.createSession(OperationType.POSSIBLY_WRITE);
try {
LOGGER.info("Users...");
for (SUser user : remoteClient.getServiceInterface().getAllUsers()) {
createUser(databaseSession, user.getOid());
}
LOGGER.info("Projects...");
for (SProject project : remoteClient.getServiceInterface().getAllProjects(false, false)) {
createProject(databaseSession, project.getOid());
}
LOGGER.info("Done");
databaseSession.commit();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
databaseSession.close();
}
final BimServerClientInterface client = bimServer.getBimServerClientFactory().create(new UsernamePasswordAuthenticationInfo(username, password));
// for (SRenderEnginePluginConfiguration renderEnginePluginConfiguration : client.getPluginInterface().getAllRenderEngines(true)) {
// if (renderEnginePluginConfiguration.getName().equals("IFC Engine DLL")) {
// client.getPluginInterface().setDefaultRenderEngine(renderEnginePluginConfiguration.getOid());
// }
// }
Path incoming = Paths.get(path);
final Map<GregorianCalendar, Key> comments = new TreeMap<>();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
for (SProject project : remoteClient.getServiceInterface().getAllProjects(false, false)) {
for (SRevision revision : remoteClient.getServiceInterface().getAllRevisionsOfProject(project.getOid())) {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(revision.getDate());
if (!revision.getComment().startsWith("generated for")) {
User user = users.get(revision.getUserId());
Path userFolder = incoming.resolve(user.getUsername());
boolean found = false;
for (Path file : PathUtils.list(userFolder)) {
if (file.getFileName().toString().endsWith(revision.getComment())) {
String dateStr = file.getFileName().toString().substring(0, 19);
Date parse = dateFormat.parse(dateStr);
GregorianCalendar fileDate = new GregorianCalendar();
fileDate.setTime(parse);
long millisDiff = Math.abs(fileDate.getTimeInMillis() - revision.getDate().getTime());
if (millisDiff > 1000 * 60 * 120) {
// 120 minutes
continue;
}
if (revision.getOid() == project.getLastRevisionId()) {
comments.put(gregorianCalendar, new Key(file, project.getOid(), revision.getComment(), revision.getDate(), revision.getUserId()));
}
found = true;
break;
}
}
if (!found) {
LOGGER.info("Not found: " + revision.getComment());
}
}
}
}
ExecutorService executorService = new ThreadPoolExecutor(1, 1, 1, TimeUnit.DAYS, new ArrayBlockingQueue<Runnable>(1000));
for (final GregorianCalendar gregorianCalendar : comments.keySet()) {
executorService.submit(new Runnable() {
@Override
public void run() {
Key key = comments.get(gregorianCalendar);
LOGGER.info("Checking in: " + key.file.getFileName().toString() + " " + Formatters.bytesToString(key.file.toFile().length()));
Project sProject = projects.get(key.poid);
try {
SDeserializerPluginConfiguration desserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", sProject.getOid());
client.checkinSync(sProject.getOid(), key.comment, desserializer.getOid(), false, key.file);
SProject updatedProject = client.getServiceInterface().getProjectByPoid(sProject.getOid());
DatabaseSession databaseSession = database.createSession(OperationType.POSSIBLY_WRITE);
try {
LOGGER.info("Done");
Project project = databaseSession.get(updatedProject.getOid(), OldQuery.getDefault());
Revision revision = project.getLastRevision();
User user = (User) databaseSession.get(users.get(key.userId).getOid(), OldQuery.getDefault());
for (Revision otherRevision : revision.getConcreteRevisions().get(0).getRevisions()) {
otherRevision.load();
otherRevision.setDate(key.date);
otherRevision.setComment(otherRevision.getComment().replace("Administrator", user.getName()));
databaseSession.store(otherRevision);
}
DateFormat m = new SimpleDateFormat("dd-MM-yyyy");
LOGGER.info("Setting date to " + m.format(key.date));
revision.setUser(user);
revision.setDate(key.date);
databaseSession.store(revision);
databaseSession.commit();
} catch (BimserverDatabaseException | ServiceException e) {
LOGGER.error("", e);
} finally {
databaseSession.close();
}
} catch (IOException | UserException | ServerException | PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
}
}
});
}
executorService.shutdown();
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (ChannelConnectionException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
} catch (ParseException e) {
LOGGER.error("", e);
} catch (IOException e) {
LOGGER.error("", e);
} catch (BimServerClientException e1) {
LOGGER.error("", e1);
} catch (Exception e2) {
LOGGER.error("", e2);
}
}
use of org.bimserver.shared.BimServerClientFactory in project BIMserver by opensourceBIM.
the class TestBigModelEmfRemote method test.
@Test
public void test() {
boolean doreuse = true;
boolean useLowLevelCalls = false;
try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
BimServerClientInterface bimServerClient = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
IfcModelInterface model = null;
if (useLowLevelCalls) {
model = bimServerClient.newModel(newProject, true);
} else {
model = new BasicIfcModel(bimServerClient.getMetaDataManager().getPackageMetaData("ifc2x3tc1"), null);
}
RichIfcModel richIfcModel = new RichIfcModel(model, !useLowLevelCalls);
IfcBuilding ifcBuilding = richIfcModel.createDefaultProjectStructure(0, 0, 0);
IfcRelAggregates buildingAggregation = richIfcModel.create(IfcRelAggregates.class);
buildingAggregation.setRelatingObject(ifcBuilding);
for (int i = 1; i <= 200; i++) {
IfcBuildingStorey ifcBuildingStorey = richIfcModel.create(IfcBuildingStorey.class);
ifcBuildingStorey.setName("Storey " + i);
ifcBuildingStorey.setCompositionType(IfcElementCompositionEnum.ELEMENT);
ifcBuildingStorey.setElevation(3000 * i);
IfcLocalPlacement storeyPlacement = richIfcModel.create(IfcLocalPlacement.class);
storeyPlacement.setRelativePlacement(richIfcModel.createBasicPosition(0, 0, i * 3000));
ifcBuildingStorey.setObjectPlacement(storeyPlacement);
buildingAggregation.getRelatedObjects().add(ifcBuildingStorey);
IfcRelAggregates storeyAggregation = richIfcModel.create(IfcRelAggregates.class);
storeyAggregation.setRelatingObject(ifcBuildingStorey);
for (int x = 1; x <= 40; x++) {
for (int y = 1; y <= 40; y++) {
createSpace(richIfcModel, richIfcModel.getDefaultRepresentationContext(), storeyPlacement, storeyAggregation, x, y, doreuse);
}
}
}
long roid = -1;
if (useLowLevelCalls) {
roid = model.commit("Initial model");
} else {
Serializer serializer = new Ifc2x3tc1StepSerializer(null);
serializer.init(model, null, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.writeToOutputStream(baos, null);
java.nio.file.Files.write(Paths.get("tmp.ifc"), baos.toByteArray());
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
SLongCheckinActionState checkinSync = bimServerClient.checkinSync(newProject.getOid(), "New", deserializer.getOid(), false, baos.size(), "newfile", new ByteArrayInputStream(baos.toByteArray()));
roid = checkinSync.getRoid();
}
SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
bimServerClient.download(roid, serializerByContentType.getOid(), new FileOutputStream(new File("created.ifc")));
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof AssertionError) {
throw (AssertionError) e;
}
fail(e.getMessage());
}
}
use of org.bimserver.shared.BimServerClientFactory in project BIMserver by opensourceBIM.
the class TestManyRevisions method start.
private void start(String[] args) {
try {
Path home = Paths.get("home");
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
pluginManager.setMetaDataManager(metaDataManager);
try (BimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, "http://localhost:8080")) {
BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
try {
SProject project = client.getServiceInterface().addProject("lots2", "ifc2x3tc1");
Path[] files = new Path[] { Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc"), Paths.get("../TestData/data/AC11-FZK-Haus-IFC - Alt.ifc") };
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
int fn = 0;
for (int i = 0; i < 20; i++) {
System.out.println(i + ": " + files[fn].getFileName().toString());
client.checkinSync(project.getOid(), "comment" + i, deserializer.getOid(), false, files[fn]);
fn = 1 - fn;
}
} catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.bimserver.shared.BimServerClientFactory in project BIMserver by opensourceBIM.
the class TestInstall method main.
public static void main(String[] args) {
ArrayList<String> pluginList = new ArrayList<>();
pluginList.add("C:/plugins/ifcplugins-0.0.15.jar");
try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
for (String each : pluginList) {
try {
DataSource fds = new FileDataSource(new File(each));
DataHandler handler = new DataHandler(fds);
client.getPluginInterface().installPluginBundleFromFile(handler, true, true);
System.out.println("Plugin " + each + " successfully installed !");
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (BimServerClientException e1) {
e1.printStackTrace();
} catch (ServiceException e1) {
e1.printStackTrace();
} catch (ChannelConnectionException e1) {
e1.printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
}
}
use of org.bimserver.shared.BimServerClientFactory 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())) {
try (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