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();
}
}
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;
}
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();
}
}
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();
}
}
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;
}
Aggregations