use of org.bimserver.plugins.Plugin in project BIMserver by opensourceBIM.
the class ServiceImpl method checkinInternal.
private Long checkinInternal(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, InputStream originalInputStream, Boolean merge, Boolean sync, final DatabaseSession session, String username, String userUsername, Project project, Path file, long newServiceId) throws BimserverDatabaseException, UserException, IOException, DeserializeException, CannotBeScheduledException {
if (getBimServer().getCheckinsInProgress().containsKey(poid)) {
throw new UserException("Checkin in progress on this project, please try again later");
}
getBimServer().getCheckinsInProgress().put(poid, getAuthorization().getUoid());
DeserializerPluginConfiguration deserializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
if (deserializerPluginConfiguration == null) {
throw new UserException("Deserializer with oid " + deserializerOid + " not found");
} else {
PluginBundleVersion pluginBundleVersion = deserializerPluginConfiguration.getPluginDescriptor().getPluginBundleVersion();
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (plugin != null) {
if (plugin instanceof DeserializerPlugin) {
DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
ObjectType settings = deserializerPluginConfiguration.getSettings();
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration(settings));
OutputStream outputStream = Files.newOutputStream(file);
InputStream inputStream = new MultiplexingInputStream(originalInputStream, outputStream);
deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
IfcModelInterface model = null;
try {
model = deserializer.read(inputStream, fileName, fileSize, null);
} finally {
inputStream.close();
}
CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge, newServiceId);
LongCheckinAction longAction = new LongCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} else if (plugin instanceof StreamingDeserializerPlugin) {
StreamingDeserializerPlugin streaminDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
ObjectType settings = deserializerPluginConfiguration.getSettings();
StreamingDeserializer streamingDeserializer = streaminDeserializerPlugin.createDeserializer(new PluginConfiguration(settings));
streamingDeserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
RestartableInputStream restartableInputStream = new RestartableInputStream(originalInputStream, file);
StreamingCheckinDatabaseAction checkinDatabaseAction = new StreamingCheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), comment, fileName, restartableInputStream, streamingDeserializer, fileSize, newServiceId, pluginBundleVersion);
LongStreamingCheckinAction longAction = new LongStreamingCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} else {
throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
}
} else {
throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
}
}
}
use of org.bimserver.plugins.Plugin in project BIMserver by opensourceBIM.
the class AbstractDownloadDatabaseAction method checkGeometry.
protected void checkGeometry(PluginConfiguration serializerPluginConfiguration, PluginManager pluginManager, IfcModelInterface model, Project project, ConcreteRevision concreteRevision, Revision revision) throws BimserverDatabaseException, GeometryGeneratingException {
boolean needsGeometry = false;
Plugin plugin = pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (plugin instanceof SerializerPlugin) {
needsGeometry = ((SerializerPlugin) plugin).needsGeometry();
}
if (needsGeometry) {
if (!revision.isHasGeometry()) {
// setProgress("Generating geometry...", -1);
// TODO When generating geometry for a partial model download (by types for example), this will fail (for example walls have no openings)
// new GeometryGenerator(bimServer).generateGeometry(authorization.getUoid(), pluginManager, getDatabaseSession(), model, project.getId(), concreteRevision.getId(), false, null);
} else {
EClass productClass = model.getPackageMetaData().getEClass("IfcProduct");
List<IdEObject> allWithSubTypes = new ArrayList<>(model.getAllWithSubTypes(productClass));
for (IdEObject ifcProduct : allWithSubTypes) {
ifcProduct.forceLoad();
GeometryInfo geometryInfo = (GeometryInfo) ifcProduct.eGet(productClass.getEStructuralFeature("geometry"));
if (geometryInfo != null) {
geometryInfo.forceLoad();
geometryInfo.getData().forceLoad();
geometryInfo.getTransformation();
geometryInfo.getMinBounds().forceLoad();
geometryInfo.getMaxBounds().forceLoad();
}
}
}
}
}
use of org.bimserver.plugins.Plugin in project BIMserver by opensourceBIM.
the class NewServicesImpl method listAvailableOutputFormats.
@Override
public List<SFormatSerializerMap> listAvailableOutputFormats(Long poid) throws ServerException, UserException {
Map<String, SFormatSerializerMap> outputs = new HashMap<>();
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
Project project = session.get(poid, OldQuery.getDefault());
try {
List<SSerializerPluginConfiguration> allSerializersForPoids = getServiceMap().get(PluginInterface.class).getAllSerializersForPoids(true, Collections.singleton(poid));
for (SSerializerPluginConfiguration pluginConfiguration : allSerializersForPoids) {
PluginDescriptor pluginDescriptor = session.get(pluginConfiguration.getPluginDescriptorId(), OldQuery.getDefault());
Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getIdentifier(), true);
String outputFormat = null;
// TODO For now only streaming serializers
if (plugin instanceof StreamingSerializerPlugin) {
outputFormat = ((StreamingSerializerPlugin) plugin).getOutputFormat(Schema.valueOf(project.getSchema().toUpperCase()));
}
if (outputFormat != null) {
SFormatSerializerMap map = outputs.get(outputFormat);
if (map == null) {
map = new SFormatSerializerMap();
map.setFormat(outputFormat);
outputs.put(outputFormat, map);
}
map.getSerializers().add(pluginConfiguration);
}
}
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
return new ArrayList<>(outputs.values());
} catch (BimserverDatabaseException e) {
return handleException(e);
}
}
use of org.bimserver.plugins.Plugin in project BIMserver by opensourceBIM.
the class PluginServiceImpl method getPluginObjectDefinition.
@Override
public SObjectDefinition getPluginObjectDefinition(Long oid) throws ServerException, UserException {
if (oid == -1) {
return null;
}
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
PluginDescriptor pluginDescriptor = session.get(oid, OldQuery.getDefault());
if (pluginDescriptor == null) {
throw new UserException("No PluginDescriptor found with oid " + oid);
}
Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getPluginClassName(), false);
if (plugin == null) {
throw new UserException("No plugin with class name " + pluginDescriptor.getPluginClassName() + " found");
}
ObjectDefinition settingsDefinition = plugin.getSettingsDefinition();
return getBimServer().getSConverter().convertToSObject(settingsDefinition);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.plugins.Plugin 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;
}
Aggregations