use of org.bimserver.plugins.serializers.SerializerException in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer2 method addNormalsAccessor.
private int addNormalsAccessor(IfcProduct ifcProduct, int bufferViewIndex, int byteOffset, int count) throws SerializerException {
if (count <= 0) {
throw new SerializerException("Count <= 0");
}
ObjectNode accessor = OBJECT_MAPPER.createObjectNode();
accessor.put("bufferView", bufferViewIndex);
accessor.put("byteOffset", byteOffset);
// accessor.put("byteStride", 12);
accessor.put("componentType", FLOAT);
accessor.put("count", count);
accessor.put("type", "VEC3");
ArrayNode min = OBJECT_MAPPER.createArrayNode();
min.add(-1d);
min.add(-1d);
min.add(-1d);
ArrayNode max = OBJECT_MAPPER.createArrayNode();
max.add(1);
max.add(1);
max.add(1);
// accessor.set("min", min);
// accessor.set("max", max);
accessors.add(accessor);
return accessors.size() - 1;
}
use of org.bimserver.plugins.serializers.SerializerException in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer2 method addIndicesAccessor.
private int addIndicesAccessor(IfcProduct ifcProduct, int bufferViewIndex, int offsetBytes, int count, int[] min, int[] max) throws SerializerException {
if (count <= 0) {
throw new SerializerException(count + " <= 0");
}
ObjectNode accessor = OBJECT_MAPPER.createObjectNode();
accessor.put("bufferView", bufferViewIndex);
accessor.put("byteOffset", offsetBytes);
// accessor.put("byteStride", 0);
accessor.put("componentType", UNSIGNED_SHORT);
accessor.put("count", count);
accessor.put("type", "SCALAR");
// ArrayNode minArray = OBJECT_MAPPER.createArrayNode();
// ArrayNode maxArray = OBJECT_MAPPER.createArrayNode();
//
// for (int i=0; i<min.length; i++) {
// minArray.add(min[i]);
// maxArray.add(max[i]);
// }
//
// accessor.set("min", minArray);
// accessor.set("max", maxArray);
accessors.add(accessor);
return accessors.size() - 1;
}
use of org.bimserver.plugins.serializers.SerializerException 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;
}
use of org.bimserver.plugins.serializers.SerializerException in project BIMserver by opensourceBIM.
the class DownloadServlet method service.
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String acceptEncoding = request.getHeader("Accept-Encoding");
boolean useGzip = false;
if (acceptEncoding != null && acceptEncoding.contains("gzip")) {
useGzip = true;
}
OutputStream outputStream = response.getOutputStream();
boolean zip = request.getParameter("zip") != null && request.getParameter("zip").equals("on");
if (useGzip && !zip) {
response.setHeader("Content-Encoding", "gzip");
outputStream = new GZIPOutputStream(response.getOutputStream());
}
String token = (String) request.getSession().getAttribute("token");
if (token == null) {
token = request.getParameter("token");
}
long topicId = -1;
if (request.getParameter("topicId") != null) {
topicId = Long.parseLong(request.getParameter("topicId"));
}
ServiceMap serviceMap = getBimServer().getServiceFactory().get(token, AccessMethod.INTERNAL);
String action = request.getParameter("action");
if (action != null) {
if (action.equals("extendeddata")) {
SExtendedData sExtendedData = serviceMap.getServiceInterface().getExtendedData(Long.parseLong(request.getParameter("edid")));
SFile file = serviceMap.getServiceInterface().getFile(sExtendedData.getFileId());
if (file.getMime() != null) {
response.setContentType(file.getMime());
}
if (file.getFilename() != null) {
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getFilename() + "\"");
}
outputStream.write(file.getData());
if (outputStream instanceof GZIPOutputStream) {
((GZIPOutputStream) outputStream).finish();
}
outputStream.flush();
return;
} else if (action.equals("getfile")) {
String type = request.getParameter("type");
if (type.equals("proto")) {
try {
String protocolBuffersFile = serviceMap.getAdminInterface().getProtocolBuffersFile(request.getParameter("name"));
outputStream.write(protocolBuffersFile.getBytes(Charsets.UTF_8));
outputStream.flush();
} catch (ServiceException e) {
LOGGER.error("", e);
}
} else if (type.equals("serverlog")) {
try {
OutputStreamWriter writer = new OutputStreamWriter(outputStream);
writer.write(serviceMap.getAdminInterface().getServerLog());
writer.flush();
} catch (ServerException e) {
LOGGER.error("", e);
} catch (UserException e) {
LOGGER.error("", e);
}
}
} else if (action.equals("getBcfImage")) {
long extendedDataId = Long.parseLong(request.getParameter("extendedDataId"));
String topicGuid = request.getParameter("topicGuid");
String name = request.getParameter("name");
BcfFile bcfFile = BcfCache.INSTANCE.get(extendedDataId);
if (bcfFile == null) {
SExtendedData extendedData = serviceMap.getServiceInterface().getExtendedData(extendedDataId);
long fileId = extendedData.getFileId();
SFile file = serviceMap.getServiceInterface().getFile(fileId);
try {
bcfFile = BcfFile.read(new ByteArrayInputStream(file.getData()), new ReadOptions(false));
BcfCache.INSTANCE.put(extendedDataId, bcfFile);
} catch (BcfException e) {
e.printStackTrace();
}
}
TopicFolder topicFolder = bcfFile.getTopicFolder(topicGuid);
if (topicFolder != null) {
byte[] data = topicFolder.getSnapshot(topicGuid + "/" + name);
if (data != null) {
response.setContentType("image/png");
IOUtils.write(data, outputStream);
if (outputStream instanceof GZIPOutputStream) {
((GZIPOutputStream) outputStream).finish();
}
outputStream.flush();
return;
}
}
}
} else {
if (request.getParameter("topicId") != null) {
topicId = Long.parseLong(request.getParameter("topicId"));
}
if (topicId == -1) {
response.getWriter().println("No valid topicId");
return;
}
SDownloadResult checkoutResult = serviceMap.getServiceInterface().getDownloadData(topicId);
if (checkoutResult == null) {
LOGGER.error("Invalid topicId: " + topicId);
} else {
DataSource dataSource = checkoutResult.getFile().getDataSource();
PluginConfiguration pluginConfiguration = new PluginConfiguration(serviceMap.getPluginInterface().getPluginSettings(checkoutResult.getSerializerOid()));
final ProgressTopic progressTopic = getBimServer().getNotificationsManager().getProgressTopic(topicId);
ProgressReporter progressReporter = new ProgressReporter() {
private long lastMax;
private long lastProgress;
private int stage = 3;
private Date start = new Date();
private String title = "Downloading...";
@Override
public void update(long progress, long max) {
if (progressTopic != null) {
LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
ds.setStart(start);
ds.setState(progress == max ? ActionState.FINISHED : ActionState.STARTED);
ds.setTitle(title);
ds.setStage(stage);
ds.setProgress((int) Math.round(100.0 * progress / max));
progressTopic.stageProgressUpdate(ds);
this.lastMax = max;
this.lastProgress = progress;
}
}
@Override
public void setTitle(String title) {
if (progressTopic != null) {
stage++;
this.title = title;
LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
ds.setStart(new Date());
ds.setState(lastProgress == lastMax ? ActionState.FINISHED : ActionState.STARTED);
ds.setTitle(title);
ds.setStage(stage);
ds.setProgress((int) Math.round(100.0 * lastProgress / lastMax));
progressTopic.stageProgressUpdate(ds);
}
}
};
try {
if (zip) {
if (pluginConfiguration.getString("ZipExtension") != null) {
response.setHeader("Content-Disposition", "inline; filename=\"" + dataSource.getName() + "." + pluginConfiguration.getString(SerializerPlugin.ZIP_EXTENSION) + "\"");
} else {
response.setHeader("Content-Disposition", "inline; filename=\"" + dataSource.getName() + ".zip" + "\"");
}
response.setContentType("application/zip");
String nameInZip = dataSource.getName() + "." + pluginConfiguration.getString(SerializerPlugin.EXTENSION);
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
zipOutputStream.putNextEntry(new ZipEntry(nameInZip));
processDataSource(zipOutputStream, dataSource, progressReporter);
try {
zipOutputStream.finish();
} catch (IOException e) {
// Sometimes it's already closed, that's no problem
}
} else {
if (request.getParameter("mime") == null) {
response.setContentType(pluginConfiguration.getString(SerializerPlugin.CONTENT_TYPE));
response.setHeader("Content-Disposition", "inline; filename=\"" + dataSource.getName() + "." + pluginConfiguration.getString(SerializerPlugin.EXTENSION) + "\"");
} else {
response.setContentType(request.getParameter("mime"));
}
processDataSource(outputStream, dataSource, progressReporter);
}
} catch (SerializerException s) {
if (s.getCause() != null && s.getCause() instanceof IOException) {
} else {
LOGGER.error("", s);
}
LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
ds.setStart(new Date());
ds.setState(ActionState.AS_ERROR);
ds.setTitle("Serialization Error");
ds.setProgress(-1);
ds.setStage(3);
ds.getErrors().add(s.getMessage());
progressTopic.stageProgressUpdate(ds);
}
}
}
if (outputStream instanceof GZIPOutputStream) {
((GZIPOutputStream) outputStream).finish();
}
outputStream.flush();
} catch (NumberFormatException e) {
LOGGER.error("", e);
response.getWriter().println("Some number was incorrectly formatted");
} catch (ServiceException e) {
LOGGER.error("", e);
response.getWriter().println(e.getUserMessage());
} catch (EOFException e) {
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of org.bimserver.plugins.serializers.SerializerException in project BIMserver by opensourceBIM.
the class Streamer method onText.
public void onText(Reader reader) {
JsonReader jsonreader = new JsonReader(reader);
JsonParser parser = new JsonParser();
JsonObject request = (JsonObject) parser.parse(jsonreader);
if (request.has("hb")) {
// Heartbeat, ignore
} else if (request.has("action")) {
if (request.get("action").getAsString().equals("download")) {
final long topicId = request.get("topicId").getAsLong();
Thread thread = new Thread() {
@Override
public void run() {
try {
LongAction<?> longAction = bimServer.getLongActionManager().getLongAction(topicId);
Writer writer = null;
if (longAction instanceof LongStreamingDownloadAction) {
LongStreamingDownloadAction longStreamingDownloadAction = (LongStreamingDownloadAction) longAction;
writer = longStreamingDownloadAction.getMessagingStreamingSerializer();
} else {
LongDownloadOrCheckoutAction longDownloadAction = (LongDownloadOrCheckoutAction) longAction;
writer = longDownloadAction.getMessagingSerializer();
}
boolean writeMessage = true;
int counter = 0;
long bytes = 0;
long start = System.nanoTime();
// TODO whenever a large object has been sent, the large buffer stays in memory until websocket closes...
ReusableLittleEndianDataOutputStream byteArrayOutputStream = new ReusableLittleEndianDataOutputStream();
GrowingByteBuffer growingByteBuffer = byteArrayOutputStream.getGrowingByteBuffer();
ProgressReporter progressReporter = new ProgressReporter() {
@Override
public void update(long progress, long max) {
longAction.updateProgress("test", (int) ((progress * 100) / max));
}
@Override
public void setTitle(String title) {
}
};
do {
byteArrayOutputStream.reset();
byteArrayOutputStream.writeLong(topicId);
writeMessage = writer.writeMessage(byteArrayOutputStream, progressReporter);
bytes += growingByteBuffer.usedSize();
streamingSocketInterface.sendBlocking(growingByteBuffer.array(), 0, growingByteBuffer.usedSize());
counter++;
} while (writeMessage);
long end = System.nanoTime();
LOGGER.info(counter + " messages written " + Formatters.bytesToString(bytes) + " in " + ((end - start) / 1000000) + " ms");
} catch (IOException e) {
// Probably closed/F5-ed browser
} catch (SerializerException e) {
LOGGER.error("", e);
}
}
};
thread.setName("Streamer " + topicId);
thread.start();
}
} else if (request.has("token")) {
String token = request.get("token").getAsString();
try {
ServiceMap serviceMap = bimServer.getServiceFactory().get(token, AccessMethod.JSON);
uoid = serviceMap.getBimServerAuthInterface().getLoggedInUser().getOid();
this.endpointid = bimServer.getEndPointManager().register(this);
JsonObject enpointMessage = new JsonObject();
enpointMessage.add("endpointid", new JsonPrimitive(endpointid));
streamingSocketInterface.send(enpointMessage);
} catch (UserException e) {
LOGGER.error("", e);
} catch (ServerException e) {
LOGGER.error("", e);
}
} else {
bimServer.getJsonHandler().execute(request, null, new NullWriter());
}
}
Aggregations