Skip to content

Commit

Permalink
More exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Jun 3, 2016
1 parent b8aa62f commit bcdae12
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,71 @@ public LongStreamingDownloadAction(BimServer bimServer, String username, String
this.jsonQuery = jsonQuery;
this.roids = roids;

setProgressTopic(bimServer.getNotificationsManager().createProgressTopic(SProgressTopicType.DOWNLOAD, "Download"));
setProgressTopic(bimServer.getNotificationsManager().createProgressTopic(SProgressTopicType.DOWNLOAD, "Download"));

DatabaseSession databaseSession = getBimServer().getDatabase().createSession();
try {
PackageMetaData packageMetaData = null;
ProjectInfo projectInfo = new ProjectInfo();

// TODO projectinfo should contain info for multiple projects/revisions, not just one

List<String> projectNames = new ArrayList<>();
for (Long roid : roids) {
Revision revision = databaseSession.get(roid, OldQuery.getDefault());
ConcreteRevision concreteRevision = revision.getConcreteRevisions().get(0);
projectInfo.setMinBounds(getBimServer().getSConverter().convertToSObject(concreteRevision.getMinBounds()));
projectInfo.setMaxBounds(getBimServer().getSConverter().convertToSObject(concreteRevision.getMaxBounds()));
projectInfo.setName("" + roids.iterator().next());
packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
projectNames.add(revision.getProject().getName() + "." + revision.getId());
break;
}

this.filename = Joiner.on("-").join(projectNames);

PluginConfiguration serializerPluginConfiguration = databaseSession.get(serializerOid, OldQuery.getDefault());
if (serializerPluginConfiguration == null) {
LOGGER.info("No serializer config found");
} else {
Plugin plugin = getBimServer().getPluginManager().getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);

JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
ObjectNode queryObject = new ObjectMapper().readValue(jsonQuery, ObjectNode.class);
Query query = converter.parseJson("query", (ObjectNode) queryObject);

downloadDescriptor = new DownloadDescriptor(roids, query, serializerOid, this.filename);

if (getBimServer().getNewDiskCacheManager().contains(downloadDescriptor)) {
DataSource dataSource = getBimServer().getNewDiskCacheManager().get(downloadDescriptor);
checkoutResult.setFile(new DataHandler(dataSource));

changeActionState(ActionState.STARTED, "Done preparing", -1);
} else {
// TODO passing a databasesession here, make sure it will be closed!!
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(databaseSession, getBimServer(), query, roids, packageMetaData);
if (plugin instanceof MessagingStreamingSerializerPlugin) {
MessagingStreamingSerializerPlugin serializerPlugin = (MessagingStreamingSerializerPlugin)plugin;
messagingStreamingSerializer = serializerPlugin.createSerializer(null);

messagingStreamingSerializer.init(queryObjectProvider, projectInfo, getBimServer().getPluginManager(), packageMetaData);

changeActionState(ActionState.STARTED, "Done preparing", -1);
} else if (plugin instanceof StreamingSerializerPlugin) {
StreamingSerializerPlugin streamingSerializerPlugin = (StreamingSerializerPlugin)plugin;
serializer = streamingSerializerPlugin.createSerializer(null);

serializer.init(queryObjectProvider, projectInfo, null, getBimServer().getPluginManager(), packageMetaData);

changeActionState(ActionState.STARTED, "Done preparing", -1);
} else {
LOGGER.error("Unimplemented " + plugin);
}
}
}
} catch (Exception e) {
error(e);
}
}

@Override
Expand All @@ -89,69 +153,7 @@ public String getDescription() {

@Override
public void execute() {
DatabaseSession databaseSession = getBimServer().getDatabase().createSession();
try {
PackageMetaData packageMetaData = null;
ProjectInfo projectInfo = new ProjectInfo();

// TODO projectinfo should contain info for multiple projects/revisions, not just one

List<String> projectNames = new ArrayList<>();
for (Long roid : roids) {
Revision revision = databaseSession.get(roid, OldQuery.getDefault());
ConcreteRevision concreteRevision = revision.getConcreteRevisions().get(0);
projectInfo.setMinBounds(getBimServer().getSConverter().convertToSObject(concreteRevision.getMinBounds()));
projectInfo.setMaxBounds(getBimServer().getSConverter().convertToSObject(concreteRevision.getMaxBounds()));
projectInfo.setName("" + roids.iterator().next());
packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
projectNames.add(revision.getProject().getName() + "." + revision.getId());
break;
}

this.filename = Joiner.on("-").join(projectNames);

PluginConfiguration serializerPluginConfiguration = databaseSession.get(serializerOid, OldQuery.getDefault());
if (serializerPluginConfiguration == null) {
LOGGER.info("No serializer config found");
} else {
Plugin plugin = getBimServer().getPluginManager().getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);

JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
ObjectNode queryObject = new ObjectMapper().readValue(jsonQuery, ObjectNode.class);
Query query = converter.parseJson("query", (ObjectNode) queryObject);

downloadDescriptor = new DownloadDescriptor(roids, query, serializerOid, this.filename);

if (getBimServer().getNewDiskCacheManager().contains(downloadDescriptor)) {
DataSource dataSource = getBimServer().getNewDiskCacheManager().get(downloadDescriptor);
checkoutResult.setFile(new DataHandler(dataSource));

changeActionState(ActionState.STARTED, "Done preparing", -1);
} else {
// TODO passing a databasesession here, make sure it will be closed!!
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(databaseSession, getBimServer(), query, roids, packageMetaData);
if (plugin instanceof MessagingStreamingSerializerPlugin) {
MessagingStreamingSerializerPlugin serializerPlugin = (MessagingStreamingSerializerPlugin)plugin;
messagingStreamingSerializer = serializerPlugin.createSerializer(null);

messagingStreamingSerializer.init(queryObjectProvider, projectInfo, getBimServer().getPluginManager(), packageMetaData);

changeActionState(ActionState.STARTED, "Done preparing", -1);
} else if (plugin instanceof StreamingSerializerPlugin) {
StreamingSerializerPlugin streamingSerializerPlugin = (StreamingSerializerPlugin)plugin;
serializer = streamingSerializerPlugin.createSerializer(null);

serializer.init(queryObjectProvider, projectInfo, null, getBimServer().getPluginManager(), packageMetaData);

changeActionState(ActionState.STARTED, "Done preparing", -1);
} else {
LOGGER.error("Unimplemented " + plugin);
}
}
}
} catch (Exception e) {
error(e);
}
}

public SCheckoutResult getCheckoutResult() throws SerializerException {
Expand Down
3 changes: 3 additions & 0 deletions BimServer/src/org/bimserver/webservices/impl/ServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,9 @@ public List<SProfileDescriptor> getAllPublicProfiles(String notificationsUrl, St

@Override
public List<SProfileDescriptor> getAllPrivateProfiles(String notificationsUrl, String serviceIdentifier) throws ServerException, UserException {
if (notificationsUrl == null) {
throw new UserException("Missing notificationsUrl");
}
requireRealUserAuthentication();
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
BimServerClientFactory factory = new JsonBimServerClientFactory(notificationsUrl, getBimServer().getServicesMap(), getBimServer().getJsonSocketReflectorFactory(), getBimServer().getReflectorFactory(), getBimServer().getMetaDataManager());
Expand Down

0 comments on commit bcdae12

Please sign in to comment.