Search in sources :

Example 1 with LongCheckoutAction

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();
    }
}
Also used : LongCheckoutAction(org.bimserver.longaction.LongCheckoutAction) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) LongDownloadOrCheckoutAction(org.bimserver.longaction.LongDownloadOrCheckoutAction) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) DownloadParameters(org.bimserver.longaction.DownloadParameters)

Aggregations

IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 DatabaseSession (org.bimserver.database.DatabaseSession)1 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)1 SUser (org.bimserver.interfaces.objects.SUser)1 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)1 DownloadParameters (org.bimserver.longaction.DownloadParameters)1 LongCheckoutAction (org.bimserver.longaction.LongCheckoutAction)1 LongDownloadOrCheckoutAction (org.bimserver.longaction.LongDownloadOrCheckoutAction)1 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)1 User (org.bimserver.models.store.User)1 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)1 SerializerException (org.bimserver.plugins.serializers.SerializerException)1 PluginException (org.bimserver.shared.exceptions.PluginException)1 ServerException (org.bimserver.shared.exceptions.ServerException)1