use of org.kuali.kfs.krad.bo.DocumentHeader in project cu-kfs by CU-CommunityApps.
the class CuFinancialMaintenanceDocumentAction method insertBONote.
/**
* Overridden to include a Rice 2.5.x fix for persisting BO note additions,
* and to delegate the fix's boolean logic to some new shouldSaveBoNoteAfterUpdate()
* and isTargetReadyForNotes() methods so that it can be further limited based on BO class and readiness.
*
* Some other cleanup has also been done to improve line lengths
* and remove certain comments, but other than that and the changes stated above,
* this method is the same as the one from KualiDocumentActionBase.
*
* @see org.kuali.kfs.kns.web.struts.action.KualiDocumentActionBase#insertBONote(
* org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward insertBONote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
Document document = kualiDocumentFormBase.getDocument();
Note newNote = kualiDocumentFormBase.getNewNote();
newNote.setNotePostedTimestampToCurrent();
String attachmentTypeCode = null;
FormFile attachmentFile = kualiDocumentFormBase.getAttachmentFile();
if (attachmentFile == null) {
GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_ATTACHMENT_FILE_PROPERTY_NAME), RiceKeyConstants.ERROR_UPLOADFILE_NULL);
}
if (newNote.getAttachment() != null) {
attachmentTypeCode = newNote.getAttachment().getAttachmentTypeCode();
}
// check authorization for adding notes
DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(document);
if (!documentAuthorizer.canAddNoteAttachment(document, attachmentTypeCode, GlobalVariables.getUserSession().getPerson())) {
throw buildAuthorizationException("annotate", document);
}
// create the attachment first, so that failure-to-create-attachment can be treated as a validation failure
Attachment attachment = null;
if (attachmentFile != null && !StringUtils.isBlank(attachmentFile.getFileName())) {
if (attachmentFile.getFileSize() == 0) {
GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_ATTACHMENT_FILE_PROPERTY_NAME), RiceKeyConstants.ERROR_UPLOADFILE_EMPTY, attachmentFile.getFileName());
} else {
String attachmentType = null;
Attachment newAttachment = kualiDocumentFormBase.getNewNote().getAttachment();
if (newAttachment != null) {
attachmentType = newAttachment.getAttachmentTypeCode();
}
attachment = getAttachmentService().createAttachment(document.getNoteTarget(), attachmentFile.getFileName(), attachmentFile.getContentType(), attachmentFile.getFileSize(), attachmentFile.getInputStream(), attachmentType);
}
}
DataDictionary dataDictionary = getDataDictionaryService().getDataDictionary();
DocumentEntry entry = dataDictionary.getDocumentEntry(document.getClass().getName());
if (entry.getDisplayTopicFieldInNotes()) {
String topicText = kualiDocumentFormBase.getNewNote().getNoteTopicText();
if (StringUtils.isBlank(topicText)) {
GlobalVariables.getMessageMap().putError(String.format("%s.%s", KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, KRADConstants.NOTE_TOPIC_TEXT_PROPERTY_NAME), RiceKeyConstants.ERROR_REQUIRED, "Note Topic (Note Topic)");
}
}
// create a new note from the data passed in
Person kualiUser = GlobalVariables.getUserSession().getPerson();
if (kualiUser == null) {
throw new IllegalStateException("Current UserSession has a null Person.");
}
Note tmpNote = getNoteService().createNote(newNote, document.getNoteTarget(), kualiUser.getPrincipalId());
ActionForward forward = checkAndWarnAboutSensitiveData(mapping, form, request, response, KRADPropertyConstants.NOTE, tmpNote.getNoteText(), "insertBONote", "");
if (forward != null) {
return forward;
}
// validate the note
boolean rulePassed = getKualiRuleService().applyRules(new AddNoteEvent(document, tmpNote));
// if the rule evaluation passed, let's add the note
if (rulePassed) {
tmpNote.refresh();
DocumentHeader documentHeader = document.getDocumentHeader();
// associate note with object now
document.addNote(tmpNote);
// maintenance document BO note should only be saved into table when document is in the PROCESSED workflow status
if (!documentHeader.getWorkflowDocument().isInitiated() && StringUtils.isNotEmpty(document.getNoteTarget().getObjectId()) && !(document instanceof MaintenanceDocument && NoteType.BUSINESS_OBJECT.getCode().equals(tmpNote.getNoteTypeCode()))) {
getNoteService().save(tmpNote);
}
// autopopulate the id since the note hasn't been persisted yet)
if (attachment != null) {
tmpNote.addAttachment(attachment);
// without the PK on the attachment I think it is safer then trying to get the sequence manually
if (!documentHeader.getWorkflowDocument().isInitiated() && StringUtils.isNotEmpty(document.getNoteTarget().getObjectId()) && !(document instanceof MaintenanceDocument && NoteType.BUSINESS_OBJECT.getCode().equals(tmpNote.getNoteTypeCode()))) {
getNoteService().save(tmpNote);
}
}
// Added some logic which saves the document and/or notes list after a BO note is added to the document
if (shouldSaveBoNoteAfterUpdate(document, tmpNote)) {
if (isTargetReadyForNotes(document)) {
getNoteService().save(tmpNote);
} else {
getDocumentService().saveDocument(document);
}
}
// reset the new note back to an empty one
kualiDocumentFormBase.setNewNote(new Note());
}
return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.krad.bo.DocumentHeader in project cu-kfs by CU-CommunityApps.
the class FinancialSystemSearchableAttribute method extractDocumentAttributes.
@Override
public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) {
if (LOG.isDebugEnabled()) {
LOG.debug("extractDocumentAttributes( " + extensionDefinition + ", " + documentWithContent + " )");
}
List<DocumentAttribute> searchAttrValues = super.extractDocumentAttributes(extensionDefinition, documentWithContent);
String docId = documentWithContent.getDocument().getDocumentId();
DocumentService docService = SpringContext.getBean(DocumentService.class);
Document doc = null;
try {
doc = docService.getByDocumentHeaderIdSessionless(docId);
} catch (WorkflowException we) {
}
if (doc != null) {
if (doc instanceof AmountTotaling && ((AmountTotaling) doc).getTotalDollarAmount() != null) {
DocumentAttributeDecimal.Builder searchableAttributeValue = DocumentAttributeDecimal.Builder.create(KFSPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT);
searchableAttributeValue.setValue(((AmountTotaling) doc).getTotalDollarAmount().bigDecimalValue());
searchAttrValues.add(searchableAttributeValue.build());
}
if (doc instanceof AccountingDocument) {
AccountingDocument accountingDoc = (AccountingDocument) doc;
searchAttrValues.addAll(harvestAccountingDocumentSearchableAttributes(accountingDoc));
}
boolean indexedLedgerDoc = false;
if (doc instanceof LaborLedgerPostingDocumentForSearching) {
LaborLedgerPostingDocumentForSearching LLPostingDoc = (LaborLedgerPostingDocumentForSearching) doc;
searchAttrValues.addAll(harvestLLPDocumentSearchableAttributes(LLPostingDoc));
indexedLedgerDoc = true;
}
if (doc instanceof GeneralLedgerPostingDocument && !indexedLedgerDoc) {
GeneralLedgerPostingDocument GLPostingDoc = (GeneralLedgerPostingDocument) doc;
searchAttrValues.addAll(harvestGLPDocumentSearchableAttributes(GLPostingDoc));
}
DocumentHeader docHeader = doc.getDocumentHeader();
if (ObjectUtils.isNotNull(docHeader) && ObjectUtils.isNotNull(docHeader.getWorkflowDocument()) && CUKFSConstants.GACC_DOCUMENT_TYPE.equalsIgnoreCase(docHeader.getWorkflowDocument().getDocumentTypeName())) {
for (AccountGlobalDetail detail : ((AccountGlobal) ((AccountGlobalMaintainableImpl) ((FinancialSystemMaintenanceDocument) doc).getNewMaintainableObject()).getBusinessObject()).getAccountGlobalDetails()) {
if (!StringUtils.isBlank(detail.getAccountNumber())) {
DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(KFSPropertyConstants.ACCOUNT_NUMBER);
searchableAttributeValue.setValue(detail.getAccountNumber());
searchAttrValues.add(searchableAttributeValue.build());
}
}
}
}
return searchAttrValues;
}
use of org.kuali.kfs.krad.bo.DocumentHeader in project cu-kfs by CU-CommunityApps.
the class GlLineServiceImpl method isDocumentAnErrorCorrection.
/**
* determines if the document is an error correction document...
*
* @param entry
* @return true if the document is an error correction else false
*/
protected boolean isDocumentAnErrorCorrection(GeneralLedgerEntry entry) {
DocumentHeader docHeader = documentHeaderService.getDocumentHeaderById(entry.getDocumentNumber());
FinancialSystemDocumentHeader fsDocumentHeader = (FinancialSystemDocumentHeader) docHeader;
return fsDocumentHeader != null && StringUtils.isNotBlank(fsDocumentHeader.getFinancialDocumentInErrorNumber());
}
use of org.kuali.kfs.krad.bo.DocumentHeader in project cu-kfs by CU-CommunityApps.
the class AmazonWebServicesBillingServiceImpl method findDocumentHeadersForAmazonDetail.
private Collection<DocumentHeader> findDocumentHeadersForAmazonDetail(AmazonAccountDetail amazonAccountDetail) {
Map fieldValues = new HashMap();
fieldValues.put(KFSPropertyConstants.EXPLANATION, buildDocumentExplanation(amazonAccountDetail.getAwsAccount()));
fieldValues.put(KFSPropertyConstants.DOCUMENT_DESCRIPTION, buildDocumentDescription(amazonAccountDetail.getBusinessPurpose()));
Collection<DocumentHeader> documentHeaders = getBusinessObjectService().findMatching(DocumentHeader.class, fieldValues);
return documentHeaders;
}
use of org.kuali.kfs.krad.bo.DocumentHeader in project cu-kfs by CU-CommunityApps.
the class PayeeACHAccountExtractServiceImplTest method createMockPAATDocument.
private MaintenanceDocument createMockPAATDocument() throws Exception {
MaintenanceDocument paatDocument = EasyMock.createMock(MaintenanceDocumentBase.class);
EasyMock.expect(paatDocument.getNewMaintainableObject()).andStubReturn(createNewMaintainableForPAAT());
EasyMock.expect(paatDocument.getDocumentHeader()).andStubReturn(new DocumentHeader());
EasyMock.expect(paatDocument.getObjectId()).andStubReturn("0");
paatDocument.addNote(EasyMock.isA(Note.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(paatDocument);
return paatDocument;
}
Aggregations