@Test public void noLockIfNoMemberIsLocked() throws ComponentLookupException, XWikiException { when(this.family.getMembers()).thenReturn(Collections.singletonList(this.notLockedPatient)); when(this.userManager.getCurrentUser()).thenReturn(this.otherUser); Assert.assertNull(this.mocker.getComponentUnderTest().getLock(this.currentDocumentReference)); }
@Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWiki xwiki = context.getWiki(); XWikiDocument xdoc; try { xdoc = xwiki.getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Family family = this.familyRepository.get(documentId); if (family == null) { return null; } List<Patient> members = family.getMembers(); if (members.isEmpty()) { return null; } User user = null; for (Patient member : members) { XWikiDocument memberXDoc = member.getXDocument(); 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); } } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; }
FamilyMembersLockModule implements LockModule { @Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWiki xwiki = context.getWiki(); XWikiDocument xdoc; try { xdoc = xwiki.getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Family family = this.familyRepository.get(documentId); if (family == null) { return null; } List<Patient> members = family.getMembers(); if (members.isEmpty()) { return null; } User user = null; for (Patient member : members) { XWikiDocument memberXDoc = member.getXDocument(); 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); } } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; } }
FamilyMembersLockModule implements LockModule { @Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWiki xwiki = context.getWiki(); XWikiDocument xdoc; try { xdoc = xwiki.getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Family family = this.familyRepository.get(documentId); if (family == null) { return null; } List<Patient> members = family.getMembers(); if (members.isEmpty()) { return null; } User user = null; for (Patient member : members) { XWikiDocument memberXDoc = member.getXDocument(); 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); } } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; }  }
FamilyMembersLockModule implements LockModule { @Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWiki xwiki = context.getWiki(); XWikiDocument xdoc; try { xdoc = xwiki.getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Family family = this.familyRepository.get(documentId); if (family == null) { return null; } List<Patient> members = family.getMembers(); if (members.isEmpty()) { return null; } User user = null; for (Patient member : members) { XWikiDocument memberXDoc = member.getXDocument(); 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); } } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; }  @Override int getPriority(); @Override DocumentLock getLock(DocumentReference doc); }
FamilyMembersLockModule implements LockModule { @Override public DocumentLock getLock(DocumentReference doc) { XWikiContext context = this.provider.get(); XWiki xwiki = context.getWiki(); XWikiDocument xdoc; try { xdoc = xwiki.getDocument(doc, context); if (xdoc == null) { return null; } String documentId = xdoc.getDocumentReference().getName(); Family family = this.familyRepository.get(documentId); if (family == null) { return null; } List<Patient> members = family.getMembers(); if (members.isEmpty()) { return null; } User user = null; for (Patient member : members) { XWikiDocument memberXDoc = member.getXDocument(); 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); } } } catch (XWikiException e) { this.logger.error("Failed to access the document lock: {}", e.getMessage(), e); } return null; }  @Override int getPriority(); @Override DocumentLock getLock(DocumentReference doc);  }