use of org.bimserver.interfaces.objects.SSerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class PluginServiceImpl method getAllSerializersForPoids.
@Override
public List<SSerializerPluginConfiguration> getAllSerializersForPoids(Boolean onlyEnabled, Set<Long> poids) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
Set<Schema> uniqueSchemas = new HashSet<>();
for (Long poid : poids) {
Project project = session.get(poid, OldQuery.getDefault());
uniqueSchemas.add(Schema.valueOf(project.getSchema().toUpperCase()));
}
Set<Schema> schemaOr = new HashSet<>();
if (uniqueSchemas.size() == 0) {
// Weird, no schemas
} else if (uniqueSchemas.size() == 1) {
// Easy, just add it, and see if there are converter targets and add those too
Schema schema = uniqueSchemas.iterator().next();
schemaOr.add(schema);
// TODO make recursive
for (Schema target : getBimServer().getSchemaConverterManager().getSchemaTargets(schema)) {
schemaOr.add(target);
}
} else if (uniqueSchemas.size() == 2) {
// This is harder, if we have 2 schema, we must figure out a way to convert to 1 schema, and then filter the allowed source schemas
Iterator<Schema> iterator = uniqueSchemas.iterator();
Schema schema1 = iterator.next();
Schema schema2 = iterator.next();
SchemaConverterFactory converter1 = getBimServer().getSchemaConverterManager().getSchemaConverterFactory(schema1, schema2);
SchemaConverterFactory converter2 = getBimServer().getSchemaConverterManager().getSchemaConverterFactory(schema2, schema1);
if (converter1 != null) {
schemaOr.add(schema1);
}
if (converter2 != null) {
schemaOr.add(schema2);
}
} else {
throw new ServerException("Unimplemented, no support for > 2 schemas");
}
UserSettings userSettings = getUserSettings(session);
List<SSerializerPluginConfiguration> sSerializers = new ArrayList<SSerializerPluginConfiguration>();
for (SerializerPluginConfiguration serializerPluginConfiguration : userSettings.getSerializers()) {
Plugin plugin = getBimServer().getPluginManager().getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (plugin instanceof SerializerPlugin) {
SerializerPlugin serializerPlugin = getBimServer().getPluginManager().getSerializerPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
for (Schema schema : serializerPlugin.getSupportedSchemas()) {
if (schemaOr.contains(schema)) {
if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
break;
}
}
}
} else if (plugin instanceof StreamingSerializerPlugin) {
StreamingSerializerPlugin streamingSerializerPlugin = (StreamingSerializerPlugin) plugin;
for (Schema schema : streamingSerializerPlugin.getSupportedSchemas()) {
if (schemaOr.contains(schema)) {
if (!onlyEnabled || (serializerPluginConfiguration.getEnabled() && serializerPluginConfiguration.getPluginDescriptor().getEnabled())) {
sSerializers.add(getBimServer().getSConverter().convertToSObject(serializerPluginConfiguration));
break;
}
}
}
}
}
Collections.sort(sSerializers, new SPluginConfigurationComparator());
return sSerializers;
} catch (Exception e) {
handleException(e);
} finally {
session.close();
}
return null;
}
use of org.bimserver.interfaces.objects.SSerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class TestGuid method main.
public static void main(String[] args) {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
try {
SProject project = client.getServiceInterface().addProject("testProject2", "ifc2x3tc1");
Long tid = client.getLowLevelInterface().startTransaction(project.getOid());
client.getLowLevelInterface().createObject(tid, "IfcWall", false);
Long roid = client.getLowLevelInterface().commitTransaction(tid, "test commit");
SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
client.download(roid, serializer.getOid(), Paths.get("test2.ifc"));
} catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.bimserver.interfaces.objects.SSerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class TestJsonSerializerMultipleRevisions method main.
public static void main(String[] args) {
try {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SSerializerPluginConfiguration jsonSerializer = client.getServiceInterface().getSerializerByContentType("application/json");
long roid1 = 65539;
long roid2 = 131075;
Long download1 = client.getServiceInterface().download(Collections.singleton(roid1), DefaultQueries.allAsString(), jsonSerializer.getOid(), true);
InputStream downloadData1 = client.getDownloadData(download1);
IOUtils.copy(downloadData1, new FileOutputStream(Paths.get("roid1.json").toFile()));
Long download2 = client.getServiceInterface().download(Collections.singleton(roid2), DefaultQueries.allAsString(), jsonSerializer.getOid(), true);
InputStream downloadData2 = client.getDownloadData(download2);
IOUtils.copy(downloadData2, new FileOutputStream(Paths.get("roid2.json").toFile()));
} catch (ServiceException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.interfaces.objects.SSerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class TestSceneJsDownload method start.
private void start() {
try {
BimServerClientInterface bimServerClient = LocalDevSetup.setupJson("http://localhost:8080");
bimServerClient.getAuthInterface().login("admin@bimserver.org", "admin");
SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByContentType("application/json");
List<SProject> projects = bimServerClient.getServiceInterface().getProjectsByName("test");
if (!projects.isEmpty()) {
SProject project = projects.get(0);
if (project.getLastRevisionId() != -1) {
long start = System.nanoTime();
Long download = bimServerClient.getServiceInterface().download(Collections.singleton(project.getLastRevisionId()), DefaultQueries.allAsString(), serializerByContentType.getOid(), true);
System.out.println(((System.nanoTime() - start) / 1000000) + " ms");
start = System.nanoTime();
InputStream inputStream = bimServerClient.getDownloadData(download);
FileOutputStream fileOutputStream = new FileOutputStream(Paths.get("test.json").toFile());
IOUtils.copy(inputStream, fileOutputStream);
fileOutputStream.close();
System.out.println(((System.nanoTime() - start) / 1000000) + " ms");
}
}
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
}
}
use of org.bimserver.interfaces.objects.SSerializerPluginConfiguration in project BIMserver by opensourceBIM.
the class TestSimultaniousDownloadWithCaching method start.
private void start() {
BimServerConfig config = new BimServerConfig();
Path homeDir = Paths.get("home");
try {
if (Files.isDirectory(homeDir)) {
PathUtils.removeDirectoryWithContent(homeDir);
}
} catch (IOException e) {
e.printStackTrace();
}
config.setClassPath(System.getProperty("java.class.path"));
config.setHomeDir(homeDir);
config.setPort(8080);
config.setStartEmbeddedWebServer(true);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
final BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
}
} catch (PluginException e2) {
e2.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
try {
final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
settingsInterface.setCacheOutputFiles(true);
settingsInterface.setGenerateGeometryOnCheckin(false);
final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
for (int i = 0; i < 20; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
c.writeToOutputStream(baos, null);
System.out.println(baos.size());
} catch (SerializerException e) {
e.printStackTrace();
}
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(downloadData.getFile().getInputStream(), baos);
System.out.println(baos.size());
}
serviceMap2.getServiceInterface().cleanupLongAction(download);
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.HOURS);
bimServer.stop();
} catch (ServerException e1) {
e1.printStackTrace();
} catch (UserException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e2) {
e2.printStackTrace();
}
}
Aggregations