use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.
the class BimServerClient method checkinSync.
public SLongCheckinActionState checkinSync(long poid, String comment, long deserializerOid, Path file, CheckinProgressHandler progressHandler) throws ServerException, UserException, PublicInterfaceNotFoundException {
long topicId = getServiceInterface().initiateCheckin(poid, deserializerOid);
ProgressHandler progressHandlerWrapper = new ProgressHandler() {
@Override
public void progress(SLongActionState state) {
progressHandler.progress(state.getTitle(), state.getProgress());
}
};
getNotificationsManager().registerProgressHandler(topicId, progressHandlerWrapper);
try (InputStream newInputStream = Files.newInputStream(file)) {
SLongCheckinActionState checkinSync = channel.checkinSync(baseAddress, token, poid, comment, deserializerOid, false, Files.size(file), file.getFileName().toString(), newInputStream, topicId);
getNotificationsManager().unregisterProgressHandler(topicId, progressHandlerWrapper);
return checkinSync;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.
the class TestGetProperties method test.
@Test
public void test() throws Exception {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path path = Paths.get("../../TestFiles/TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc");
SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {
@Override
public void progress(String title, int progress) {
System.out.println(title + ": " + progress);
}
});
ClientIfcModel model = client.getModel(project, actionState.getRoid(), false, false);
for (IfcWall wall : model.getAllWithSubTypes(IfcWall.class)) {
String layerName = IfcUtils.getStringProperty(wall, "Layername");
Assert.assertNotNull(layerName);
Assert.assertFalse(layerName.isEmpty());
}
}
}
Thread.sleep(1000);
}
use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.
the class TestDeserializerErrorCode2 method test.
@Test
public void test() throws Exception {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
Path path = Paths.get("../../TestFiles/TestData/data/ADT-FZK-Haus-2005-2006.ifc");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {
@Override
public void progress(String title, int progress) {
System.out.println(title + ": " + progress);
}
});
Assert.assertEquals(DeserializerErrorCode.IFC_SCHEMA_NOT_SUPPORTED_BY_DESERIALIZER, ErrorCode.fromCode(checkinSync.getDeserializeErrorCode()));
}
}
}
use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.
the class TestSimultaneousCheckin method test.
@Test
public void test() throws Exception {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {
@Override
public void progress(String title, int progress) {
System.out.println(title + ": " + progress);
}
});
}
Thread.sleep(1000);
}
}
use of org.bimserver.plugins.services.CheckinProgressHandler in project BIMserver by opensourceBIM.
the class TestCheckinWithProgress method test.
@Test
public void test() {
try {
// Create a new BimServerClient with authentication
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// When you use the channel for checkin/download calls, all data will have to be converted to the used channel's format, for example for JSON, binary data will be Base64 encoded, which will make things slower and larger
// The alternative is to use the Servlets, those will also use compression where possible
// Using the channel is slower
boolean useChannel = true;
// Create a new project
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Find a deserializer to use
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
// Checkin
// if (useChannel) {
// progressId = bimServerClient.getServiceInterface().checkin(newProject.getOid(), "test", deserializer.getOid(), ifcFile.toFile().length(), ifcFile.getFileName().toString(), new DataHandler(new FileDataSource(ifcFile.toFile())), true, true);
// } else {
SLongCheckinActionState longActionState = bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"), new CheckinProgressHandler() {
@Override
public void progress(String title, int progress) {
System.out.println(title + ": " + progress);
}
});
if (longActionState.getState() == SActionState.FINISHED) {
// Find a serializer
SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
// Get the project details
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
// Download the latest revision (the one we just checked in)
if (useChannel) {
Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), true);
SLongActionState downloadState = bimServerClient.getRegistry().getProgress(topicId);
if (downloadState.getState() == SActionState.FINISHED) {
InputStream inputStream = bimServerClient.getServiceInterface().getDownloadData(topicId).getFile().getInputStream();
IOUtils.copy(inputStream, new ByteArrayOutputStream());
System.out.println("Success");
}
} else {
// Note: sync: false
Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(newProject.getLastRevisionId()), DefaultQueries.allAsString(), serializer.getOid(), false);
InputStream downloadData = bimServerClient.getDownloadData(topicId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(downloadData, baos);
System.out.println(baos.size() + " bytes downloaded");
}
} else {
System.out.println(longActionState.getState());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations