Search in sources :

Example 36 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class PluginServiceImpl method setDefaultModelCompare.

public void setDefaultModelCompare(final Long oid) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SetUserSettingDatabaseAction action = new SetUserSettingDatabaseAction(session, getInternalAccessMethod(), getAuthorization(), new UserSettingsSetter() {

            @Override
            public void set(UserSettings userSettings) {
                userSettings.setDefaultModelCompare(find(userSettings.getModelCompares(), oid));
            }
        });
        session.executeAndCommitAction(action);
    } catch (BimserverDatabaseException e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserSettingsSetter(org.bimserver.database.actions.UserSettingsSetter) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) SetUserSettingDatabaseAction(org.bimserver.database.actions.SetUserSettingDatabaseAction)

Example 37 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class QueryObjectProvider method next.

@Override
public HashMapVirtualObject next() throws BimserverDatabaseException {
    if (start == -1) {
        start = System.nanoTime();
    }
    try {
        while (!stack.isEmpty()) {
            if (stack.size() > MAX_STACK_SIZE) {
                dumpEndQuery();
                throw new BimserverDatabaseException("Query stack size > 10000, probably a bug, please report");
            }
            stackFrame = stack.peek();
            if (stackFrame.isDone()) {
                stack.pop();
                continue;
            }
            stackFramesProcessed++;
            if (stackFramesProcessed > MAX_STACK_FRAMES_PROCESSED) {
                dumpEndQuery();
                throw new BimserverDatabaseException("Too many stack frames processed ( > " + MAX_STACK_FRAMES_PROCESSED + "), probably a bug, or possibly a very large model, please report");
            }
            boolean done = stackFrame.process();
            stackFrame.setDone(done);
            if (stackFrame instanceof ObjectProvidingStackFrame) {
                HashMapVirtualObject currentObject = ((ObjectProvidingStackFrame) stackFrame).getCurrentObject();
                if (currentObject != null) {
                    if (!oidsRead.contains(currentObject.getOid())) {
                        oidsRead.add(currentObject.getOid());
                        return currentObject;
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new BimserverDatabaseException(e);
    }
    dumpEndQuery();
    return null;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryException(org.bimserver.database.queries.om.QueryException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 38 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class LongDownloadOrCheckoutAction method executeAction.

protected void executeAction(BimDatabaseAction<? extends IfcModelInterface> action, DownloadParameters downloadParameters, DatabaseSession session, boolean commit) throws BimserverDatabaseException, UserException, NoSerializerFoundException, ServerException {
    try {
        if (action == null) {
            checkoutResult = new SCheckoutResult();
            checkoutResult.setFile(new CachingDataHandler(getBimServer().getDiskCacheManager(), downloadParameters));
            checkoutResult.setSerializerOid(downloadParameters.getSerializerOid());
        } else {
            Revision revision = session.get(StorePackage.eINSTANCE.getRevision(), downloadParameters.getRoid(), OldQuery.getDefault());
            if (revision == null) {
                throw new UserException("Revision with roid " + downloadParameters.getRoid() + " not found");
            }
            // Little hack to make
            revision.getProject().getGeoTag().load();
            // sure this is
            // lazily loaded,
            // because after the
            // executeAndCommitAction
            // the session won't
            // be usable
            IfcModelInterface ifcModel = session.executeAndCommitAction(action);
            // Session is closed after this
            DatabaseSession newSession = getBimServer().getDatabase().createSession();
            RenderEnginePlugin renderEnginePlugin = null;
            try {
                PluginConfiguration serializerPluginConfiguration = newSession.get(StorePackage.eINSTANCE.getPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
                if (serializerPluginConfiguration != null) {
                    if (serializerPluginConfiguration instanceof MessagingSerializerPluginConfiguration) {
                        try {
                            messagingSerializer = getBimServer().getSerializerFactory().createMessagingSerializer(getUserName(), ifcModel, downloadParameters);
                        } catch (SerializerException e) {
                            e.printStackTrace();
                        }
                    } else if (serializerPluginConfiguration instanceof SerializerPluginConfiguration) {
                        RenderEnginePluginConfiguration renderEngine = ((SerializerPluginConfiguration) serializerPluginConfiguration).getRenderEngine();
                        if (renderEngine != null) {
                            renderEnginePlugin = getBimServer().getPluginManager().getRenderEnginePlugin(renderEngine.getPluginDescriptor().getPluginClassName(), true);
                        }
                        checkoutResult = convertModelToCheckoutResult(revision.getProject(), getUserName(), ifcModel, renderEnginePlugin, downloadParameters);
                    }
                }
            } catch (BimserverDatabaseException e) {
                LOGGER.error("", e);
            } finally {
                newSession.close();
            }
        }
    } finally {
        done();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SCheckoutResult(org.bimserver.interfaces.objects.SCheckoutResult) RenderEnginePlugin(org.bimserver.plugins.renderengine.RenderEnginePlugin) SerializerException(org.bimserver.plugins.serializers.SerializerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) Revision(org.bimserver.models.store.Revision) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException)

Example 39 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class LongGenericAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        action.setDatabaseSession(session);
        session.executeAndCommitAction(action, new ProgressHandler() {

            private int count;

            @Override
            public void progress(int current, int max) {
                if (count == 0) {
                    updateProgress("Saving to database (" + fileName + ")", current * 100 / max);
                } else {
                    updateProgress("Saving to database (" + fileName + ", " + count + " try)", current * 100 / max);
                }
            }

            @Override
            public void retry(int count) {
                this.count = count;
            }
        }, new RollbackListener() {

            @Override
            public void rollback() {
                try {
                    action.rollback();
                } catch (BimserverDatabaseException e) {
                    LOGGER.error("", e);
                }
            }
        });
    } catch (Exception e) {
        if (e instanceof UserException) {
        } else if (e instanceof BimserverConcurrentModificationDatabaseException) {
        // Ignore
        } else {
            LOGGER.error("", e);
        }
        error(e);
    } finally {
        try {
            action.close();
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        session.close();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, action.doneMessage(), 100);
        }
        done();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) RollbackListener(org.bimserver.database.RollbackListener) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 40 with BimserverDatabaseException

use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.

the class RequestPasswordChangeDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    final User user = getUserByUserName(username);
    if (user == null) {
        throw new UserException("User with username \"" + username + "\" not found");
    }
    final String token = GeneratorUtils.generateToken();
    user.setValidationToken(Hashers.getSha256Hash(token));
    user.setValidationTokenCreated(new Date());
    getDatabaseSession().store(user);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            if (MailSystem.isValidEmailAddress(user.getUsername())) {
                EmailMessage message = bimServer.getMailSystem().createMessage();
                String body = null;
                String subject = null;
                try {
                    InternetAddress addressFrom = new InternetAddress(bimServer.getServerSettingsCache().getServerSettings().getEmailSenderAddress());
                    message.setFrom(addressFrom);
                    InternetAddress[] addressTo = new InternetAddress[1];
                    addressTo[0] = new InternetAddress(user.getUsername());
                    message.setRecipients(Message.RecipientType.TO, addressTo);
                    Map<String, Object> context = new HashMap<String, Object>();
                    context.put("name", user.getName());
                    context.put("username", user.getUsername());
                    if (includeSiteAddress) {
                        context.put("siteaddress", bimServer.getServerSettingsCache().getServerSettings().getSiteAddress());
                    }
                    context.put("validationlink", resetUrl + "&username=" + user.getUsername() + "&uoid=" + user.getOid() + "&validationtoken=" + token + (includeSiteAddress ? ("&address=" + bimServer.getServerSettingsCache().getServerSettings().getSiteAddress()) : ""));
                    body = bimServer.getTemplateEngine().process(context, TemplateIdentifier.PASSWORD_RESET_EMAIL_BODY);
                    subject = bimServer.getTemplateEngine().process(context, TemplateIdentifier.PASSWORD_RESET_EMAIL_SUBJECT);
                    message.setContent(body, "text/html");
                    message.setSubject(subject.trim());
                    message.send();
                } catch (Exception e) {
                    LOGGER.error(body);
                    throw new UserException(e.getMessage());
                }
            }
        }
    });
    return null;
}
Also used : EmailMessage(org.bimserver.mail.EmailMessage) InternetAddress(javax.mail.internet.InternetAddress) User(org.bimserver.models.store.User) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)123 DatabaseSession (org.bimserver.database.DatabaseSession)56 UserException (org.bimserver.shared.exceptions.UserException)30 EClass (org.eclipse.emf.ecore.EClass)24 User (org.bimserver.models.store.User)20 ByteBuffer (java.nio.ByteBuffer)19 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)18 ServerSettings (org.bimserver.models.store.ServerSettings)18 IOException (java.io.IOException)16 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)16 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)16 SServerSettings (org.bimserver.interfaces.objects.SServerSettings)16 ServerException (org.bimserver.shared.exceptions.ServerException)15 UserSettings (org.bimserver.models.store.UserSettings)12 ServiceException (org.bimserver.shared.exceptions.ServiceException)11 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 ArrayList (java.util.ArrayList)9 IdEObject (org.bimserver.emf.IdEObject)9 Project (org.bimserver.models.store.Project)9 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)9