Search in sources :

Example 76 with ServerException

use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.

the class ServiceImpl method checkinFromUrlSync.

@Override
public SLongCheckinActionState checkinFromUrlSync(Long poid, String comment, Long deserializerOid, String fileName, String urlString, Boolean merge) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    final DatabaseSession readOnlySession = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    String username = "Unknown";
    String userUsername = "Unknown";
    try {
        Long topicId = initiateCheckin(poid, deserializerOid);
        User user = (User) readOnlySession.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
        username = user.getName();
        userUsername = user.getUsername();
        Project project = readOnlySession.get(poid, OldQuery.getDefault());
        if (project == null) {
            throw new UserException("No project found with poid " + poid);
        }
        URL url = new URL(urlString);
        URLConnection openConnection = url.openConnection();
        InputStream input = openConnection.getInputStream();
        Path incomingFile = getIncomingFileName(fileName, urlString, userUsername);
        return checkinInternal(topicId, poid, comment, deserializerOid, (long) openConnection.getContentLength(), fileName, input, merge, true, readOnlySession, username, userUsername, project, incomingFile, -1);
    // DeserializerPluginConfiguration deserializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
    // if (deserializerPluginConfiguration == null) {
    // throw new UserException("Deserializer with oid " + deserializerOid + " not found");
    // }
    // OutputStream outputStream = Files.newOutputStream(file);
    // InputStream inputStream = new MultiplexingInputStream(input, outputStream);
    // DeserializerPlugin deserializerPlugin = (DeserializerPlugin) getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
    // ObjectType settings = deserializerPluginConfiguration.getSettings();
    // 
    // Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration(settings));
    // deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
    // 
    // IfcModelInterface model = deserializer.read(inputStream, fileName, 0, null);
    // 
    // CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge);
    // LongCheckinAction longAction = new LongCheckinAction(-1L, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
    // getBimServer().getLongActionManager().start(longAction);
    // if (sync) {
    // longAction.waitForCompletion();
    // }
    // return longAction.getProgressTopic().getKey().getId();
    } catch (UserException e) {
        throw e;
    } catch (Throwable e) {
        LOGGER.error("", e);
        throw new ServerException(e);
    } finally {
        readOnlySession.close();
    }
}
Also used : Path(java.nio.file.Path) Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) ServerException(org.bimserver.shared.exceptions.ServerException) DatabaseSession(org.bimserver.database.DatabaseSession) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiplexingInputStream(org.bimserver.utils.MultiplexingInputStream) InputStream(java.io.InputStream) UserException(org.bimserver.shared.exceptions.UserException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 77 with ServerException

use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.

the class ServiceImpl method getVolume.

@Override
public Double getVolume(Long roid, Long oid) throws UserException, ServerException {
    requireAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        BimDatabaseAction<Double> action = new GetVolumeDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, oid, getAuthorization());
        return session.executeAndCommitAction(action);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) 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) GetVolumeDatabaseAction(org.bimserver.database.actions.GetVolumeDatabaseAction)

Example 78 with ServerException

use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.

the class ServiceImpl method clone.

@Override
public Long clone(Long roid, String projectName, String comment, Boolean sync) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        CloneToNewProjectDatabaseAction action = new CloneToNewProjectDatabaseAction(session, getInternalAccessMethod(), getBimServer(), getAuthorization(), roid, projectName, comment);
        User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
        String username = user.getName();
        String userUsername = user.getUsername();
        LongCopyAction longAction = new LongCopyAction(getBimServer(), username, userUsername, getAuthorization(), action);
        getBimServer().getLongActionManager().start(longAction);
        if (sync) {
            longAction.waitForCompletion();
        }
        return longAction.getProgressTopic().getKey().getId();
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) LongCopyAction(org.bimserver.longaction.LongCopyAction) CloneToNewProjectDatabaseAction(org.bimserver.database.actions.CloneToNewProjectDatabaseAction) 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)

Example 79 with ServerException

use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.

the class ServiceImpl method uploadFile.

@Override
public Long uploadFile(SFile file) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        File convertFromSObject = getBimServer().getSConverter().convertFromSObject(file, session.create(File.class), session);
        UploadFileDatabaseAction action = new UploadFileDatabaseAction(session, getInternalAccessMethod(), convertFromSObject);
        return session.executeAndCommitAction(action);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) File(org.bimserver.models.store.File) SFile(org.bimserver.interfaces.objects.SFile) BcfFile(org.opensourcebim.bcf.BcfFile) 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) UploadFileDatabaseAction(org.bimserver.database.actions.UploadFileDatabaseAction)

Example 80 with ServerException

use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.

the class ServiceImpl method getIfcHeader.

@Override
public SIfcHeader getIfcHeader(Long croid) throws UserException, ServerException {
    requireAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        BimDatabaseAction<SIfcHeader> action = new GetIfcHeaderDatabaseAction(getBimServer(), session, getInternalAccessMethod(), croid, getAuthorization());
        return session.executeAndCommitAction(action);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : GetIfcHeaderDatabaseAction(org.bimserver.database.actions.GetIfcHeaderDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) SIfcHeader(org.bimserver.interfaces.objects.SIfcHeader) 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)

Aggregations

ServerException (org.bimserver.shared.exceptions.ServerException)281 UserException (org.bimserver.shared.exceptions.UserException)277 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)242 IOException (java.io.IOException)234 DatabaseSession (org.bimserver.database.DatabaseSession)234 ServiceException (org.bimserver.shared.exceptions.ServiceException)127 SerializerException (org.bimserver.plugins.serializers.SerializerException)124 PluginException (org.bimserver.shared.exceptions.PluginException)124 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)122 MalformedURLException (java.net.MalformedURLException)120 BcfException (org.opensourcebim.bcf.BcfException)120 UnsupportedEncodingException (java.io.UnsupportedEncodingException)119 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)119 MessagingException (javax.mail.MessagingException)119 AddressException (javax.mail.internet.AddressException)119 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)119 ArrayList (java.util.ArrayList)30 SProject (org.bimserver.interfaces.objects.SProject)30 User (org.bimserver.models.store.User)27 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)24