本文整理汇总了Java中org.kuali.rice.krad.util.GlobalVariables.setUserSession方法的典型用法代码示例。如果您正苦于以下问题:Java GlobalVariables.setUserSession方法的具体用法?Java GlobalVariables.setUserSession怎么用?Java GlobalVariables.setUserSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kuali.rice.krad.util.GlobalVariables
的用法示例。
在下文中一共展示了GlobalVariables.setUserSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
GlobalVariables.setMessageMap(new MessageMap());
GlobalVariables.setUserSession(new UserSession("admin"));
TravelDestination newTravelDestination = new TravelDestination();
newTravelDestination.setTravelDestinationName(DESTINATION_NAME);
newTravelDestination.setCountryCd(COUNTRY_CODE);
newTravelDestination.setStateCd(STATE_CODE);
TRAVEL_DESTINATION_ID = KRADServiceLocator.getDataObjectService().save(
newTravelDestination, PersistenceOption.FLUSH).getTravelDestinationId();
Document newDocument = KRADServiceLocatorWeb.getDocumentService().getNewDocument(TravelAuthorizationDocument.class);
newDocument.getDocumentHeader().setDocumentDescription(DOCUMENT_DESCRIPTION);
TravelAuthorizationDocument newTravelAuthorizationDocument = (TravelAuthorizationDocument) newDocument;
newTravelAuthorizationDocument.setCellPhoneNumber(CELL_PHONE_NUMBER);
newTravelAuthorizationDocument.setTripDestinationId(TRAVEL_DESTINATION_ID);
DOCUMENT_NUMBER = KRADServiceLocatorWeb.getDocumentService().saveDocument(
newTravelAuthorizationDocument).getDocumentNumber();
}
示例2: setUp
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
GlobalVariables.setMessageMap(new MessageMap());
GlobalVariables.setUserSession(new UserSession("admin"));
TravelerDetail newTravelerDetail = new TravelerDetail();
newTravelerDetail.setPrincipalId(PRINCIPAL_ID);
TRAVELER_DETAIL_ID = KRADServiceLocator.getDataObjectService().save(
newTravelerDetail, PersistenceOption.FLUSH).getId();
TravelDestination newTravelDestination = new TravelDestination();
newTravelDestination.setTravelDestinationName(DESTINATION_NAME);
newTravelDestination.setCountryCd(COUNTRY_CODE);
newTravelDestination.setStateCd(STATE_CODE);
TRAVEL_DESTINATION_ID = KRADServiceLocator.getDataObjectService().save(
newTravelDestination, PersistenceOption.FLUSH).getTravelDestinationId();
TravelMileageRate newTravelMileageRate = new TravelMileageRate();
newTravelMileageRate.setMileageRateCd(MILEAGE_RATE_CODE);
newTravelMileageRate.setMileageRateName(MILEAGE_RATE_NAME);
newTravelMileageRate.setMileageRate(MILEAGE_RATE);
MILEAGE_RATE_ID = KRADServiceLocator.getDataObjectService().save(
newTravelMileageRate, PersistenceOption.FLUSH).getMileageRateId();
}
示例3: testGetRouteHeader
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* Tests the loading of a RouteHeaderVO using the WorkflowInfo.
*
* Verifies that an NPE no longer occurrs as mentioned in KULRICE-765.
*/
@Test
public void testGetRouteHeader() throws Exception {
// ensure the UserSession is cleared out (could have been set up by other tests)
GlobalVariables.setUserSession(null);
String ewestfalPrincipalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("ewestfal")
.getPrincipalId();
GlobalVariables.setUserSession(new UserSession("ewestfal"));
WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(ewestfalPrincipalId,
"TestDocumentType");
String documentId = workflowDocument.getDocumentId();
assertNotNull(documentId);
Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId);
assertNotNull(document);
assertEquals(documentId, document.getDocumentId());
assertEquals(DocumentStatus.INITIATED, document.getStatus());
}
示例4: verifyDelete
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* deletes the provided locks while checking for error conditions
*
* @param userId - the user id to use in creating a session
* @param lockIds - a list lock ids to delete
* @param expectedException - the expected exception's class
* @param expectException - true if an exception is expected on delete
* @see PessimisticLockService#delete(String)
* @throws WorkflowException
*/
private void verifyDelete(String userId, List<String> lockIds, Class expectedException, boolean expectException) throws WorkflowException {
GlobalVariables.setUserSession(new UserSession(userId));
for (String lockId : lockIds) {
try {
KRADServiceLocatorWeb.getPessimisticLockService().delete(lockId);
if (expectException) {
fail("Expected exception when deleting lock with id '" + lockId + "' for user '" + userId + "'");
}
} catch (Exception e) {
if (!expectException) {
fail("Did not expect exception when deleting lock with id '" + lockId + "' for user '" + userId + "' but got exception of type '" + e.getClass().getName() + "'");
}
if (expectedException != null) {
// if we have an expected exception
if (!expectedException.isAssignableFrom(e.getClass())) {
fail("Expected exception of type '" + expectedException.getName() + "' when deleting lock with id '" + lockId + "' for user '" + userId + "' but got exception of type '" + e.getClass().getName() + "'");
}
}
}
}
}
示例5: preHandle
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* Before the controller executes the user session is set on GlobalVariables
* and messages are cleared, in addition setup for the history manager and a check on missing session
* forms is performed.
*
* {@inheritDoc}
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
checkHandlerMethodAccess(request, handler);
final ParameterService parameterService = CoreFrameworkServiceLocator.getParameterService();
if (parameterService.getParameterValueAsBoolean(KRADConstants.KUALI_RICE_SYSTEM_NAMESPACE, ParameterConstants.ALL_COMPONENT, CsrfValidator.CSRF_PROTECTION_ENABLED_PARAM) && !CsrfValidator.validateCsrf(request, response)) {
return false;
}
final UserSession session = KRADUtils.getUserSessionFromRequest(request);
GlobalVariables.setUserSession(session);
GlobalVariables.clear();
createUifFormManagerIfNecessary(request);
// add the HistoryManager for storing HistoryFlows to the session
if (request.getSession().getAttribute(UifConstants.HistoryFlow.HISTORY_MANAGER) == null) {
request.getSession().setAttribute(UifConstants.HistoryFlow.HISTORY_MANAGER, new HistoryManager());
}
ProcessLogger.trace("pre-handle");
return true;
}
示例6: assertBlanketApproveAttributes
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
protected void assertBlanketApproveAttributes(Document document, DocumentType documentType, String principalId) throws Exception {
KRADServiceLocatorWeb.getDocumentService().blanketApproveDocument(document, "Blanket Approved SearchAttributeIndexTestDocument", null);
assertDDSearchableAttributesWork(documentType, principalId, "routeLevelCount",
new String[] {"1","0","2","3","7"},
new int[] {0, 0, 0, 1, 0}
);
assertDDSearchableAttributesWork(documentType, principalId, "constantString",
new String[] {"hippo","monkey"},
new int[] {1, 0}
);
assertDDSearchableAttributesWork(documentType, principalId, "routedString",
new String[] {"routing","hippo"},
new int[] {1, 0}
);
GlobalVariables.setUserSession(null);
}
示例7: testExistenceChecks
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Test
/**
* tests validation on the extension attribute
*
* <p>The values given for attributes that are foreign keys should represent existing objects when auto-update is set to false</p>
*/
public void testExistenceChecks() throws Exception {
Account account = new Account();
((AccountExtension)account.getExtension()).setAccountTypeCode( "XYZ" ); // invalid account type
account.setName("Test Name");
account.setNumber("1234567");
GlobalVariables.setUserSession(new UserSession("quickstart"));
MaintenanceDocument document = (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument(
"AccountMaintenanceDocument");
assertNotNull( "new document must not be null", document );
document.getDocumentHeader().setDocumentDescription( getClass().getSimpleName() + "test" );
document.getOldMaintainableObject().setDataObject(null);
document.getOldMaintainableObject().setDataObjectClass(account.getClass());
document.getNewMaintainableObject().setDataObject(account);
document.getNewMaintainableObject().setDataObjectClass(account.getClass());
boolean failedAsExpected = false;
try {
document.validateBusinessRules( new RouteDocumentEvent(document) );
} catch ( ValidationException expected ) {
failedAsExpected = true;
}
assertTrue( "validation should have failed", failedAsExpected );
System.out.println( "document errors: " + GlobalVariables.getMessageMap() );
assertTrue( "there should be errors", GlobalVariables.getMessageMap().getErrorCount() > 0 );
assertTrue("should be an error on the account type code", GlobalVariables.getMessageMap().doesPropertyHaveError(
"document.newMaintainableObject.dataObject.extension.accountTypeCode"));
assertTrue("account type code should have an existence error", GlobalVariables.getMessageMap().fieldHasMessage(
"document.newMaintainableObject.dataObject.extension.accountTypeCode", "error.existence"));
}
示例8: testAttachmentContents
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Test
/**
* tests {@link Attachment#getAttachmentContents()}
*/
public void testAttachmentContents() throws Exception {
try{
FileWriter out = new FileWriter("dummy.txt");
out.write("Hello testAttachmentContent");
out.close();
File dummyFile = new File("dummy.txt");
Note dummyNote = new Note();
InputStream inStream = new FileInputStream("dummy.txt");
GlobalVariables.setUserSession(new UserSession("quickstart"));
Person kualiUser = GlobalVariables.getUserSession().getPerson();
Note parentNote = KRADServiceLocator.getNoteService().createNote(dummyNote, dummyAttachment, kualiUser.getPrincipalId());
dummyAttachment = KRADServiceLocator.getAttachmentService().createAttachment( parentNote,
"dummy.txt",
"MimeTypeCode",
(int) (long) dummyFile.length(),
inStream,
"AttachmentTypeCode");
String result ="";
BufferedReader in = new BufferedReader(new InputStreamReader(dummyAttachment.getAttachmentContents()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
inStream.close();
assertEquals("Testing attachmentContents in AttachmentTest","Hello testAttachmentContent",result );
}
finally{
new File("dummy.txt").delete();
}
}
示例9: processPreprocess
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* This overridden method ...
*
* @see org.apache.struts.action.RequestProcessor#processPreprocess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response) {
final UserSession session = KRADUtils.getUserSessionFromRequest(request);
if (session == null) {
throw new IllegalStateException("the user session has not been established");
}
GlobalVariables.setUserSession(session);
GlobalVariables.clear();
return super.processPreprocess(request, response);
}
示例10: blanketApproveTest
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Test
public void blanketApproveTest() throws Exception {
final String principalName = "admin";
final String principalId = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName).getPrincipalId();
GlobalVariables.setUserSession(new UserSession(principalName));
Document document = DOCUMENT_FIXTURE.NORMAL_DOCUMENT.getDocument();
document.getDocumentHeader().setDocumentDescription("Blanket Approved SAIndexTestDoc");
final DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(SEARCH_ATTRIBUTE_INDEX_DOCUMENT_TEST_DOC_TYPE);
assertBlanketApproveAttributes(document, documentType, principalId);
}
示例11: regularApproveTest
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* Tests that a document, which goes through a regular approval process, is indexed correctly
*/
@Test
public void regularApproveTest() throws Exception {
final String principalName = "quickstart";
final String principalId = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName).getPrincipalId();
GlobalVariables.setUserSession(new UserSession(principalName));
RouteContext.clearCurrentRouteContext();
Document document = DOCUMENT_FIXTURE.NORMAL_DOCUMENT.getDocument();
document.getDocumentHeader().setDocumentDescription("Routed SAIndexTestDoc");
final DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(SEARCH_ATTRIBUTE_INDEX_DOCUMENT_TEST_DOC_TYPE);
assertApproveAttributes(document, documentType, principalId);
}
示例12: testDocTypeSecurityAndResponsibilityAndVisibilityWorkgroupNames
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* Tests if the deprecated "workgroup" elements on the "security" and "responsibility" tags are being parsed and assigned properly.
* Also tests the functionality of the "isMemberOfWorkgroup" element on rule attributes.
*
* @throws Exception
*/
@Test
public void testDocTypeSecurityAndResponsibilityAndVisibilityWorkgroupNames() throws Exception {
// Ensure that the document type called "DocumentType02" has the correct group defined for its responsibility on "TestRule1".
RuleBaseValues testRule = KEWServiceLocator.getRuleService().getRuleByName("TestRule1");
assertNotNull("TestRule1 should not be null", testRule);
assertEquals("There should be exactly one responsibility on TestRule1", 1, testRule.getRuleResponsibilities().size());
RuleResponsibilityBo testResp = testRule.getRuleResponsibilities().get(0);
assertNotNull("The responsibility on TestRule1 should not be null", testResp);
assertEquals("The responsibility on TestRule1 has the wrong type", KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID, testResp.getRuleResponsibilityType());
Group testGroup = KimApiServiceLocator.getGroupService().getGroup(testResp.getRuleResponsibilityName());
assertGroupIsCorrect("<responsibility><workgroup>", "TestWorkgroup", "KR-WKFLW", testGroup);
// Ensure that the "DocumentType02" document type has a properly-working "isMemberOfWorkgroup" element on its attribute.
String[] testPrincipalNames = {"rkirkend", "quickstart"};
boolean[] visibleStates = {true, false};
// Make sure that the rule attribute is visible for "rkirkend" but not for "quickstart".
for (int i = 0; i < testPrincipalNames.length; i++) {
LOG.info("Testing visibility of the rule attribute for user '" + testPrincipalNames[i] + "'");
// Set up a new KEW UserSession in a manner similar to that of WorkflowInfoTest.
GlobalVariables.setUserSession(null);
String testPrincipalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(testPrincipalNames[i]).getPrincipalId();
GlobalVariables.setUserSession(new UserSession(testPrincipalNames[i]));
// Get the visibility of the rule attribute, which should be dependent on how the UserSession compares with the "isMemberOfWorkgroup" element.
StandardGenericXMLSearchableAttribute searchableAttribute = new StandardGenericXMLSearchableAttribute();
ExtensionDefinition ed = createExtensionDefinition("SearchableAttributeVisible");
List<RemotableAttributeField> remotableAttributeFields = searchableAttribute.getSearchFields(ed, "DocumentType02");
List<Row> rowList = FieldUtils.convertRemotableAttributeFields(remotableAttributeFields);
assertEquals("The searching rows list should have exactly one element", 1, rowList.size());
assertEquals("The searching row should have exactly one field", 1, rowList.get(0).getFields().size());
assertEquals("The rule attribute field does not have the expected visibility", visibleStates[i],
rowList.get(0).getField(0).isColumnVisible());
}
// Ensure that the document type called "DocTypeWithSecurity" has the correct group defined for its <security> section.
DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName("DocTypeWithSecurity");
List<Group> testGroups = docType.getDocumentTypeSecurity().getWorkgroups();
assertEquals("docTypeSecurity should have exactly one group in its security section", 1, testGroups.size());
assertGroupIsCorrect("<security><workgroup>", "NonSIT", "KR-WKFLW", testGroups.get(0));
}
示例13: documentExists
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
/**
* @see org.kuali.rice.krad.service.DocumentService#documentExists(java.lang.String)
*/
@Override
public boolean documentExists(String documentHeaderId) {
// validate parameters
if (StringUtils.isBlank(documentHeaderId)) {
throw new IllegalArgumentException("invalid (blank) documentHeaderId");
}
boolean internalUserSession = false;
try {
// KFSMI-2543 - allowed method to run without a user session so it can be used
// by workflow processes
if (GlobalVariables.getUserSession() == null) {
internalUserSession = true;
GlobalVariables.setUserSession(new UserSession(KRADConstants.SYSTEM_USER));
GlobalVariables.clear();
}
// look for workflowDocumentHeader, since that supposedly won't break the transaction
if (getWorkflowDocumentService().workflowDocumentExists(documentHeaderId)) {
// look for docHeaderId, since that fails without breaking the transaction
return documentHeaderService.getDocumentHeaderById(documentHeaderId) != null;
}
return false;
} finally {
// if a user session was established for this call, clear it our
if (internalUserSession) {
GlobalVariables.clear();
GlobalVariables.setUserSession(null);
}
}
}
示例14: tearDown
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Override
public void tearDown() throws Exception {
GlobalVariables.setMessageMap(new MessageMap());
GlobalVariables.setUserSession(null);
super.tearDown();
}
示例15: service
import org.kuali.rice.krad.util.GlobalVariables; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String documentId = null;
try {
UserSession userSession = KRADUtils.getUserSessionFromRequest(request);
if (userSession == null) {
throw new AuthenticationException("Failed to locate a user session for request.");
}
GlobalVariables.setUserSession(userSession);
RequestParser requestParser = new RequestParser(request);
String inputCommand = requestParser.getParameterValue("command");
if (StringUtils.equals(inputCommand, "initiate")){
requestParser.setParameterValue("userAction","initiate");
}
String edlName = requestParser.getParameterValue("edlName");
if (edlName == null) {
edlName = requestParser.getParameterValue("docTypeName");//this is for 'WorkflowQuicklinks'
}
EDLController edlController = null;
if (edlName == null) {
documentId = requestParser.getParameterValue("docId");
if (documentId == null) {
String docFormKey = requestParser.getParameterValue(KRADConstants.DOC_FORM_KEY);
if (docFormKey != null) {
Document document = (Document) GlobalVariables.getUserSession().retrieveObject(docFormKey);
Element documentState = EDLXmlUtils.getDocumentStateElement(document);
documentId = EDLXmlUtils.getChildElementTextValue(documentState, "docId");
requestParser.setAttribute(KRADConstants.DOC_FORM_KEY, docFormKey);
}
if (documentId == null) {
throw new WorkflowRuntimeException("No edl name or document id detected");
}
}
requestParser.setAttribute("docId", documentId);
edlController = EdlServiceLocator.getEDocLiteService().getEDLControllerUsingDocumentId(documentId);
} else {
edlController = EdlServiceLocator.getEDocLiteService().getEDLControllerUsingEdlName(edlName);
}
//TODO Fix this in a better way (reworking the command structure maybe?)
//fix for KULRICE-4057 to make sure we don't destory docContent on empty command params
if(inputCommand == null && requestParser.getParameterValue("docId") != null && !"POST".equals(request.getMethod())){
//make sure these are the only params on the request (paging passed undefined input command as well...
if(!(request.getParameterMap().size() > 2)){//ensures ONLY documentId was passed
requestParser.setParameterValue("command", "displayDocSearchView");
LOG.info("command parameter was not passed with the request, and only document ID was. Defaulted command to 'displayDocSearchView' to ensure docContent remains.");
}
}
EDLControllerChain controllerChain = new EDLControllerChain();
controllerChain.addEdlController(edlController);
//TODO Do we not want to set the content type for the response?
controllerChain.renderEDL(requestParser, response);
} catch (Exception e) {
LOG.error("Error processing EDL", e);
outputError(request, response, e, documentId);
} finally {
GlobalVariables.setUserSession(null);
}
}