public Date getLockingDate() { try { XWikiLock lock = this.doc.getLock(getXWikiContext()); if (lock != null && !getXWikiContext().getUser().equals(lock.getUserName())) { return lock.getDate(); } else { return null; } } catch (XWikiException e) { return null; } }
public void setLock(String userName, XWikiContext context) throws XWikiException { XWikiLock lock = new XWikiLock(getId(), userName); getStore(context).saveLock(lock, context, true); }
public XWikiLock() { this.setDate(null); this.setUserName(null); this.setDocId(0); }
public String getLockingUser() { try { XWikiLock lock = this.doc.getLock(getXWikiContext()); if (lock != null && !getXWikiContext().getUser().equals(lock.getUserName())) { return lock.getUserName(); } else { return ""; } } catch (XWikiException e) { return ""; } }
public XWikiLock getLock(XWikiContext context) throws XWikiException { XWikiLock theLock = getStore(context).loadLock(getId(), context, true); if (theLock != null) { int timeout = context.getWiki().getXWikiPreferenceAsInt("lock_Timeout", 30 * 60, context); if (theLock.getDate().getTime() + timeout * 1000 < new Date().getTime()) { getStore(context).deleteLock(theLock, context, true); theLock = null; } } return theLock; }
public void saveLock(XWikiLock lock, XWikiContext context, boolean bTransaction) throws XWikiException { try { if (bTransaction) { checkHibernate(context); bTransaction = beginTransaction(context); } Session session = getSession(context); Query query = session.createQuery("select lock.docId from XWikiLock as lock where lock.docId = :docId"); query.setLong("docId", lock.getDocId()); if (query.uniqueResult() == null) { session.save(lock); } else { session.update(lock); } if (bTransaction) { endTransaction(context, true); } } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_LOCK, "Exception while locking document", e); } finally { try { if (bTransaction) { endTransaction(context, false); } } catch (Exception e) { } } }
public boolean getLocked() { try { XWikiLock lock = this.doc.getLock(getXWikiContext()); if (lock != null && !getXWikiContext().getUser().equals(lock.getUserName())) { return true; } else { return false; } } catch (Exception e) { return false; } }
@Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWikiDocument xdoc; try { xdoc = context.getWiki().getDocument(doc, context); if (xdoc == null) { return null; } XWikiLock xlock = xdoc.getLock(context); User user = this.userManager.getUser(xlock.getUserName()); if (xlock != null && !user.getId().equals(this.userManager.getCurrentUser().getId())) { Set<String> actions = Collections.singleton("edit"); return new DocumentLock(user, xlock.getDate(), this.tm.translate("locks.documentInUse", user.getName()), actions, true); } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; } }
/** * return true if can be locked return null in case of an error return false in all the other cases * * @param fullName * @param force * @return */ @Override public Boolean lockDocument(String fullName, boolean force) throws XWikiGWTException { try { XWikiContext context = getXWikiContext(); XWikiDocument doc = context.getWiki().getDocument(fullName, context); if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), fullName, context)) { /* Setup a lock */ XWikiLock lock = doc.getLock(context); if ((lock == null) || (lock.getUserName().equals(context.getUser())) || force) { if (lock != null) doc.removeLock(context); doc.setLock(context.getUser(), context); return Boolean.valueOf(true); } else return Boolean.valueOf(false); } else return Boolean.valueOf(false); } catch (Exception e) { throw getXWikiGWTException(e); } }
public XWikiLock(long docId, String userName) { this.setDocId(docId); this.setUserName(userName); this.setDate(new Date()); }
query.setLong("docId", docId); if (query.uniqueResult() != null) { lock = new XWikiLock(); session.load(lock, new Long(docId));
XWikiLock xlock = memberXDoc.getLock(context); if (xlock != null) { user = this.userManager.getUser(xlock.getUserName()); date = (date.before(xlock.getDate())) ? xlock.getDate() : date; Set<String> actions = Collections.singleton("edit"); return new DocumentLock(user, date, this.tm.translate("family.locks.familyMemberInUse"),
if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) doc.setLock(context.getUser(), context); } catch (Exception e) {
XWikiLock xlock = memberXDoc.getLock(context); if (xlock != null) { user = this.userManager.getUser(xlock.getUserName()); Set<String> actions = Collections.singleton("edit"); return new DocumentLock(user, xlock.getDate(), this.tm.translate("family.locks.familyMemberInUse"), actions, false);
if ((lock == null) || (username.equals(lock.getUserName()))) { if ("inline".equals(request.get("action"))) { doc.setLock(username, context);
@Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWikiDocument xdoc; try { xdoc = context.getWiki().getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Patient patient = this.patientRepository.getPatientById(documentId); if (patient == null) { return null; } XWikiLock xlock = xdoc.getLock(context); User user = this.userManager.getUser(xlock.getUserName()); if (xlock != null && !user.getId().equals(this.userManager.getCurrentUser().getId())) { Set<String> actions = Collections.singleton("edit"); return new DocumentLock(user, xlock.getDate(), this.tm.translate("patient.locks.patientInUse", user.getName()), actions, false); } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; } }
if (lock != null && lock.getUserName().equals(username)) { if ("inline".equals(request.get("action"))) { doc.removeLock(context);
@Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWikiDocument xdoc; try { xdoc = context.getWiki().getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Patient patient = this.patientRepository.getPatientById(documentId); if (patient == null) { return null; } XWikiLock xlock = xdoc.getLock(context); User user = this.userManager.getUser(xlock.getUserName()); if (xlock != null && !user.getId().equals(this.userManager.getCurrentUser().getId())) { Set<String> actions = Collections.singleton("edit"); return new DocumentLock(user, xlock.getDate(), this.tm.translate("patient.locks.patientInUse", user.getName()), actions, false); } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; } }
if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) { tdoc.setLock(context.getUser(), context);
@Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWikiDocument xdoc; try { xdoc = context.getWiki().getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Family family = this.familyRepository.getFamilyById(documentId); if (family == null) { return null; } XWikiLock xlock = xdoc.getLock(context); User user = this.userManager.getUser(xlock.getUserName()); if (xlock != null && !user.getId().equals(this.userManager.getCurrentUser().getId())) { Set<String> actions = Collections.singleton("edit"); return new DocumentLock(user, xlock.getDate(), this.tm.translate("family.locks.familyInUse", user.getName()), actions, false); } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; } }