/** @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); } } }
/** * This method will use the DocumentService to create a new document. The documentTypeName is * gathered by using MaintenanceDocumentDictionaryService which uses Account class to get the * document type name. * * @param AccountCreationStatusDTO * @return document returns a new document for the account document type or null if there is an * exception thrown. */ public Document createCGAccountMaintenanceDocument( AccountCreationStatusDTO accountCreationStatus) { boolean internalUserSession = false; try { if (GlobalVariables.getUserSession() == null) { internalUserSession = true; GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER)); GlobalVariables.clear(); } Document document = getDocumentService() .getNewDocument( SpringContext.getBean(MaintenanceDocumentDictionaryService.class) .getDocumentTypeName(Account.class)); return document; } catch (Exception e) { accountCreationStatus.setErrorMessages( GlobalVariablesExtractHelper.extractGlobalVariableErrors()); accountCreationStatus.setStatus(KcConstants.KcWebService.STATUS_KC_FAILURE); return null; } finally { // if a user session was established for this call, clear it our if (internalUserSession) { GlobalVariables.clear(); GlobalVariables.setUserSession(null); } } }
/** * The default implementation - this retrieves all documents by a list of documentHeader for a * given class. * * @see * org.kuali.rice.krad.service.DocumentService#getDocumentsByListOfDocumentHeaderIds(java.lang.Class, * java.util.List) */ @Override public List<Document> getDocumentsByListOfDocumentHeaderIds( Class<? extends Document> documentClass, List<String> documentHeaderIds) throws WorkflowException { // validate documentHeaderIdList and contents if (documentHeaderIds == null) { throw new IllegalArgumentException("invalid (null) documentHeaderId list"); } int index = 0; for (String documentHeaderId : documentHeaderIds) { if (StringUtils.isBlank(documentHeaderId)) { throw new IllegalArgumentException( "invalid (blank) documentHeaderId at list index " + index); } index++; } 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(); } // retrieve all documents that match the document header ids List<? extends Document> rawDocuments = getLegacyDataAdapter().findByDocumentHeaderIds(documentClass, documentHeaderIds); // post-process them List<Document> documents = new ArrayList<Document>(); for (Document document : rawDocuments) { WorkflowDocument workflowDocument = getWorkflowDocumentService() .loadWorkflowDocument( document.getDocumentNumber(), GlobalVariables.getUserSession().getPerson()); document = postProcessDocument(document.getDocumentNumber(), workflowDocument, document); documents.add(document); } return documents; } finally { // if a user session was established for this call, clear it our if (internalUserSession) { GlobalVariables.clear(); GlobalVariables.setUserSession(null); } } }
/** * This method check to see if the user can create the account maintenance document and set the * user session * * @param String principalId * @return boolean */ protected boolean isValidUser(String principalId) { PersonService personService = SpringContext.getBean(PersonService.class); if (principalId == null) { return false; } Person user = personService.getPerson(principalId); if (user == null) { return false; } DocumentAuthorizer documentAuthorizer = new MaintenanceDocumentAuthorizerBase(); if (documentAuthorizer.canInitiate( SpringContext.getBean(MaintenanceDocumentDictionaryService.class) .getDocumentTypeName(Account.class), user)) { // set the user session so that the user name can be displayed in the saved document GlobalVariables.setUserSession(new UserSession(user.getPrincipalName())); return true; } LOG.error( KcUtils.getErrorMessage( KcConstants.AccountCreationService.ERROR_KC_DOCUMENT_INVALID_USER, new String[] {principalId})); return false; }
@Override public String getReceivingDeliveryCampusCode(PurchaseOrderDocument po) { if (GlobalVariables.getUserSession() == null) { GlobalVariables.setUserSession(new UserSession(KRADConstants.SYSTEM_USER)); GlobalVariables.clear(); } return super.getReceivingDeliveryCampusCode(po); }
@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); KNSGlobalVariables.clear(); return true; }
/** * This is temporary until workflow 2.0 and reads from a table to get documents whose status has * changed to A (approved - no outstanding approval actions requested) * * @param documentHeaderId * @return Document * @throws WorkflowException */ @Override public Document getByDocumentHeaderId(String documentHeaderId) throws WorkflowException { if (documentHeaderId == null) { throw new IllegalArgumentException("invalid (null) 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(); } WorkflowDocument workflowDocument = null; if (LOG.isDebugEnabled()) { LOG.debug("Retrieving doc id: " + documentHeaderId + " from workflow service."); } workflowDocument = getWorkflowDocumentService() .loadWorkflowDocument(documentHeaderId, GlobalVariables.getUserSession().getPerson()); UserSessionUtils.addWorkflowDocument(GlobalVariables.getUserSession(), workflowDocument); Class<? extends Document> documentClass = getDocumentClassByTypeName(workflowDocument.getDocumentTypeName()); // retrieve the Document Document document = getLegacyDataAdapter().findByDocumentHeaderId(documentClass, documentHeaderId); return postProcessDocument(documentHeaderId, workflowDocument, document); } finally { // if a user session was established for this call, clear it out if (internalUserSession) { GlobalVariables.clear(); GlobalVariables.setUserSession(null); } } }
@Test 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(); PersistableBusinessObject parentNote = KRADServiceLocator.getNoteService() .createNote(dummyNote, dummyAttachment, kualiUser.getPrincipalId()); dummyAttachment = KRADServiceLocator.getAttachmentService() .createAttachment( parentNote, "dummy.txt", "MimeTypeCode", (int) (long) dummyFile.length(), inStream, "AttachmentTypeCode"); String result = ""; DataInputStream in = new DataInputStream(dummyAttachment.getAttachmentContents()); while (in.available() != 0) { result += in.readLine(); } inStream.close(); assertEquals( "Testing attachmentContents in AttachmentTest", "Hello testAttachmentContent", result); } finally { new File("dummy.txt").delete(); } }
@Before public void setUp() throws Exception { GlobalVariables.setUserSession(new UserSession("quickstart")); }
@Before public void setUp() { GlobalVariables.setUserSession(new UserSession("quickstart")); }
@Before public void setUp() throws Exception { rule = new UnitMaintenanceDocumentRule(); GlobalVariables.setUserSession(new UserSession("quickstart")); }
@After public void tearDown() throws Exception { GlobalVariables.setUserSession(null); }
@Before public void setUp() throws Exception { GlobalVariables.setUserSession(new UserSession("quickstart")); protocolVersionService = KraServiceLocator.getService(ProtocolVersionService.class); }