use of org.bimserver.client.json.JsonBimServerClientFactory 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();
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.checkin(sProject.getOid(), key.comment, desserializer.getOid(), false, Flow.SYNC, key.file);
SProject updatedProject = client.getServiceInterface().getProjectByPoid(sProject.getOid());
DatabaseSession databaseSession = database.createSession();
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.client.json.JsonBimServerClientFactory 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.checkin(project.getOid(), "comment" + i, deserializer.getOid(), false, Flow.SYNC, 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.client.json.JsonBimServerClientFactory 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.client.json.JsonBimServerClientFactory in project BIMserver by opensourceBIM.
the class TriggerImportDataRemote method main.
public static void main(String[] args) {
/*
* Args:
* 0: Address of new server
* 1: Username
* 2: Password
* 3: Address of old server
* 4: Local path to incoming folder of old server, this local path has to be available on the new server, so you have to copy it from the old server
*/
try {
Path home = Paths.get("home");
Path tmp = home.resolve("tmp");
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
MetaDataManager metaDataManager = new MetaDataManager(tmp);
pluginManager.setMetaDataManager(metaDataManager);
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, args[0])) {
BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo(args[1], args[2]));
client.getServiceInterface().importData(args[3], args[1], args[2], args[4]);
} catch (Exception e) {
e.printStackTrace();
}
} catch (PluginException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
}
}
use of org.bimserver.client.json.JsonBimServerClientFactory 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