use of org.bimserver.longaction.LongCheckoutAction in project BIMserver by opensourceBIM.
the class ServiceImpl method checkout.
@Override
public Long checkout(Long roid, Long serializerOid, Boolean sync) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
getAuthorization().canDownload(roid);
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
User user = null;
try {
SerializerPluginConfiguration serializerPluginConfiguration = (SerializerPluginConfiguration) session.get(serializerOid, OldQuery.getDefault());
// org.bimserver.plugins.serializers.Serializer serializer = getBimServer().getEmfSerializerFactory().get(serializerOid).createSerializer(new org.bimserver.plugins.serializers.PluginConfiguration());
if (serializerPluginConfiguration == null) {
throw new UserException("No serializer with id " + serializerOid + " could be found");
}
if (!serializerPluginConfiguration.getPluginDescriptor().getPluginClassName().equals("org.bimserver.ifc.step.serializer.Ifc4StepSerializerPlugin") && !serializerPluginConfiguration.getPluginDescriptor().getPluginClassName().equals("org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializerPlugin")) {
throw new UserException("Only IFC allowed when checking out");
}
DownloadParameters downloadParameters = new DownloadParameters(getBimServer(), DownloadType.DOWNLOAD_PROJECTS);
downloadParameters.setRoid(roid);
downloadParameters.setSerializerOid(serializerOid);
user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
LongDownloadOrCheckoutAction longDownloadAction = new LongCheckoutAction(getBimServer(), user.getName(), user.getUsername(), downloadParameters, getAuthorization(), getInternalAccessMethod());
try {
getBimServer().getLongActionManager().start(longDownloadAction);
} catch (CannotBeScheduledException e) {
LOGGER.error("", e);
}
if (sync) {
longDownloadAction.waitForCompletion();
}
return longDownloadAction.getProgressTopic().getKey().getId();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
Aggregations