use of org.bimserver.schemaconverter.SchemaConverterFactory 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.schemaconverter.SchemaConverterFactory in project BIMserver by opensourceBIM.
the class SerializerFactory method create.
public Serializer create(Project project, String username, IfcModelInterface model, RenderEnginePlugin renderEnginePlugin, DownloadParameters downloadParameters) throws SerializerException {
DatabaseSession session = bimDatabase.createSession();
try {
SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
if (serializerPluginConfiguration != null) {
SerializerPlugin serializerPlugin = (SerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (serializerPlugin != null) {
ObjectType settings = serializerPluginConfiguration.getSettings();
Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
if (!serializerPlugin.getSupportedSchemas().contains(model.getPackageMetaData().getSchema())) {
SchemaConverterFactory converterFactory = null;
for (Schema schema : serializerPlugin.getSupportedSchemas()) {
converterFactory = bimServer.getSchemaConverterManager().getSchemaConverterFactory(model.getPackageMetaData().getSchema(), schema);
if (converterFactory != null) {
break;
}
}
if (converterFactory == null) {
throw new SerializerException("No usable converter found for schema " + model.getPackageMetaData().getSchema() + " for serializer " + serializerPlugin.getClass().getName());
}
try {
IfcModel targetModel = new BasicIfcModel(bimServer.getMetaDataManager().getPackageMetaData(converterFactory.getTargetSchema().getEPackageName()), new HashMap<Integer, Long>(), (int) model.size());
SchemaConverter converter = converterFactory.create(model, targetModel);
converter.convert();
model = targetModel;
} catch (SchemaConverterException e) {
throw new SerializerException(e);
} catch (IfcModelInterfaceException e) {
throw new SerializerException(e);
}
}
if (serializer != null) {
try {
ProjectInfo projectInfo = new ProjectInfo();
projectInfo.setName(project.getName());
projectInfo.setDescription(project.getDescription());
GeoTag geoTag = project.getGeoTag();
if (geoTag != null && geoTag.getEnabled()) {
projectInfo.setX(geoTag.getX());
projectInfo.setY(geoTag.getY());
projectInfo.setZ(geoTag.getZ());
projectInfo.setDirectionAngle(geoTag.getDirectionAngle());
} else {
projectInfo.setX(4.8900);
projectInfo.setY(52.3700);
}
projectInfo.setAuthorName(username);
serializer.init(model, projectInfo, true);
return serializer;
} catch (NullPointerException e) {
LOGGER.error("", e);
}
}
}
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
session.close();
}
return null;
}
Aggregations