本文整理汇总了Java中org.kuali.rice.krad.document.Document.getCustomLockDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getCustomLockDescriptor方法的具体用法?Java Document.getCustomLockDescriptor怎么用?Java Document.getCustomLockDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kuali.rice.krad.document.Document
的用法示例。
在下文中一共展示了Document.getCustomLockDescriptor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertCustomLockDescriptorsAreWorking
import org.kuali.rice.krad.document.Document; //导入方法依赖的package包/类
/**
* A convenience method for testing the custom lock descriptors of documents (and on the maintainables of maintenance documents).
*
* @param testDoc The document to test pessimistic locking on (or the maintenance document with maintainables to test on).
* @param LOCK_KEY The UserSession object key to use for storing the lock descriptor's key.
* @param LOCK_VALUE1 One possible object to store in a UserSession for generating lock descriptors on the testDoc.
* @param LOCK_VALUE2 Another possible object to store in a UserSession for generating lock descriptors on the testDoc.
*
* @throws Exception
*/
private void assertCustomLockDescriptorsAreWorking(Document testDoc, final String LOCK_KEY, final Serializable LOCK_VALUE1,
final Serializable LOCK_VALUE2) throws Exception {
PessimisticLockService lockService = KRADServiceLocatorWeb.getPessimisticLockService();
// Have "quickstart" establish a pessimistic lock on the document by using a custom lock descriptor that only locks part of the document.
UserSession quickstartSession = new UserSession("quickstart");
Person[] allPersons = { quickstartSession.getPerson(), null };
Map<String,String> editMode = new HashMap<String,String>();
editMode.put(AuthorizationConstants.EditMode.FULL_ENTRY, KRADConstants.KUALI_DEFAULT_TRUE_VALUE);
GlobalVariables.getUserSession().addObject(LOCK_KEY, LOCK_VALUE1);
String[] allDescriptors = { testDoc.getCustomLockDescriptor(quickstartSession.getPerson()), null };
assertNotNull("The document should have generated a custom lock descriptor", allDescriptors[0]);
Map <?,?> finalModes = lockService.establishLocks(testDoc, editMode, quickstartSession.getPerson());
// Verify that the lock was actually established and that the expected custom lock descriptor was used.
assertCorrectLocksAreInPlace(true, finalModes, 1, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
// Attempt to establish the same lock again, which should change nothing since "quickstart" already has the lock.
editMode = new HashMap<String,String>();
editMode.put(AuthorizationConstants.EditMode.FULL_ENTRY, KRADConstants.KUALI_DEFAULT_TRUE_VALUE);
GlobalVariables.getUserSession().addObject(LOCK_KEY, LOCK_VALUE1);
lockService.establishLocks(testDoc, editMode, quickstartSession.getPerson());
assertCorrectLocksAreInPlace(false, null, 1, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
// Now check to make sure that a different user (such as "admin") cannot establish a lock using the same lock descriptor.
UserSession adminSession = new UserSession("admin");
editMode = new HashMap<String,String>();
editMode.put(AuthorizationConstants.EditMode.FULL_ENTRY, KRADConstants.KUALI_DEFAULT_TRUE_VALUE);
GlobalVariables.getUserSession().addObject(LOCK_KEY, LOCK_VALUE1);
assertEquals("The document should have generated the same lock descriptors for both 'quickstart' and 'admin'",
allDescriptors[0], testDoc.getCustomLockDescriptor(adminSession.getPerson()));
finalModes = lockService.establishLocks(testDoc, editMode, adminSession.getPerson());
assertCorrectLocksAreInPlace(false, finalModes, 1, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
// Ensure that "admin" can establish a lock that has a different lock descriptor.
allPersons[1] = adminSession.getPerson();
editMode = new HashMap<String,String>();
editMode.put(AuthorizationConstants.EditMode.FULL_ENTRY, KRADConstants.KUALI_DEFAULT_TRUE_VALUE);
GlobalVariables.getUserSession().addObject(LOCK_KEY, LOCK_VALUE2);
allDescriptors[1] = testDoc.getCustomLockDescriptor(adminSession.getPerson());
assertNotNull("The document should have generated a custom lock descriptor", allDescriptors[1]);
assertNotSame("'quickstart' and 'admin' should have different custom lock descriptors now", allDescriptors[0], allDescriptors[1]);
finalModes = lockService.establishLocks(testDoc, editMode, adminSession.getPerson());
assertCorrectLocksAreInPlace(true, finalModes, 2, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
// Verify that "quickstart" cannot acquire the lock owned by "admin".
editMode = new HashMap<String,String>();
editMode.put(AuthorizationConstants.EditMode.FULL_ENTRY, KRADConstants.KUALI_DEFAULT_TRUE_VALUE);
GlobalVariables.getUserSession().addObject(LOCK_KEY, LOCK_VALUE2);
lockService.establishLocks(testDoc, editMode, quickstartSession.getPerson());
assertCorrectLocksAreInPlace(false, null, 2, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
// After "admin" releases his lock, check to make sure that "quickstart" can now acquire it.
lockService.releaseAllLocksForUser(testDoc.getPessimisticLocks(), allPersons[1], allDescriptors[1]);
testDoc.refreshPessimisticLocks();
assertCorrectLocksAreInPlace(false, null, 1, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
allPersons[1] = allPersons[0];
editMode = new HashMap<String,String>();
editMode.put(AuthorizationConstants.EditMode.FULL_ENTRY, KRADConstants.KUALI_DEFAULT_TRUE_VALUE);
GlobalVariables.getUserSession().addObject(LOCK_KEY, LOCK_VALUE2);
finalModes = lockService.establishLocks(testDoc, editMode, quickstartSession.getPerson());
assertCorrectLocksAreInPlace(true, finalModes, 2, testDoc.getPessimisticLocks(), allPersons, allDescriptors);
// Release all the locks when done.
GlobalVariables.getUserSession().removeObject(LOCK_KEY);
lockService.releaseAllLocksForUser(testDoc.getPessimisticLocks(), allPersons[0]);
testDoc.refreshPessimisticLocks();
assertTrue("There should not be any pessimistic locks present on the document", testDoc.getPessimisticLocks().isEmpty());
}
示例2: isPessimisticLockNeeded
import org.kuali.rice.krad.document.Document; //导入方法依赖的package包/类
/**
* Determines whether to add a pessimistic lock on the {@code document} for {@code user} based on the current
* pessimistic locks and edit modes.
*
* @param document the document on which the locks will be established
* @param user the user for which the locks are being established
* @param canEdit whether the user currently can edit the document
*
* @return true if a pessimistic lock should be added, false otherwise
*/
protected boolean isPessimisticLockNeeded(Document document, Person user, boolean canEdit) {
List<String> userOwnedLockDescriptors = new ArrayList<String>();
Map<String, Set<String>> otherOwnedLockDescriptors = new HashMap<String,Set<String>>();
// create the two lock containers that help determine whether to add a pessimistic lock
for (PessimisticLock pessimisticLock : document.getPessimisticLocks()) {
if (pessimisticLock.isOwnedByUser(user)) {
userOwnedLockDescriptors.add(pessimisticLock.getLockDescriptor());
} else {
if (!otherOwnedLockDescriptors.containsKey(pessimisticLock.getLockDescriptor())) {
otherOwnedLockDescriptors.put(pessimisticLock.getLockDescriptor(), new HashSet<String>());
}
String otherOwnerPrincipalId = pessimisticLock.getOwnedByUser().getPrincipalId();
otherOwnedLockDescriptors.get(pessimisticLock.getLockDescriptor()).add(otherOwnerPrincipalId);
}
}
// double check whether the existing pessimistic locks are sane
checkExistingPessimisticLocks(document, userOwnedLockDescriptors, otherOwnedLockDescriptors);
// if no one has a lock on this document, then the document can be locked if the user can edit it
if (userOwnedLockDescriptors.isEmpty() && otherOwnedLockDescriptors.isEmpty()) {
return canEdit;
}
// if custom locking is turned on, then if the current user doesn't have a custom lock on this document and no
// one else has a custom lock on this document, then the document can be locked if the user can edit it
if (document.useCustomLockDescriptors()) {
String customLockDescriptor = document.getCustomLockDescriptor(user);
boolean userOwnsCustomLockDescriptor = userOwnedLockDescriptors.contains(customLockDescriptor);
boolean otherOwnsCustomLockDescriptor = otherOwnedLockDescriptors.containsKey(customLockDescriptor);
if (!userOwnsCustomLockDescriptor && !otherOwnsCustomLockDescriptor) {
return canEdit;
}
}
return false;
}