use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.
the class CUFinancialSystemDocumentServiceImpl method writeNote.
protected void writeNote(AccountingDocument accountingDocument, String noteText) {
DocumentService documentService = SpringContext.getBean(DocumentService.class);
// Put a note on the document to record the change to the address
try {
// String noteText = buildLineChangedNoteText(newAccountingLine, oldAccountingLine);
int noteMaxSize = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength("Note", "noteText");
// Break up the note into multiple pieces if the note is too large to fit in the database field.
while (noteText.length() > noteMaxSize) {
int fromIndex = 0;
fromIndex = noteText.lastIndexOf(';', noteMaxSize);
String noteText1 = noteText.substring(0, fromIndex);
Note note1 = documentService.createNoteFromDocument(accountingDocument, noteText1);
accountingDocument.addNote(note1);
noteText = noteText.substring(fromIndex);
}
Note note = documentService.createNoteFromDocument(accountingDocument, noteText);
accountingDocument.addNote(note);
} catch (Exception e) {
LOG.error("Exception while attempting to create or add note: " + e);
}
}
use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.
the class CUFinancialSystemDocumentServiceImpl method checkAccountingLinesForChanges.
/**
* new == null, old == null : no change; line deleted previously.
* new == blah, old == blah : no change
* new == blah, old == meh : changed
* new == null, old == blah : deleted
* new == blah, old == null : added
* @throws WorkflowException
*
* @see org.kuali.kfs.sys.document.service.FinancialSystemDocumentService#checkAccountingLinesForChanges(org.kuali.kfs.sys.document.AccountingDocument)
*/
public void checkAccountingLinesForChanges(AccountingDocument accountingDocument) {
DocumentService docService = SpringContext.getBean(DocumentService.class);
AccountingDocument savedDoc = null;
try {
savedDoc = (AccountingDocument) docService.getByDocumentHeaderId(accountingDocument.getDocumentNumber());
} catch (WorkflowException we) {
LOG.error("Unable to retrieve document number " + accountingDocument.getDocumentNumber() + " to evaluate accounting line changes");
}
if (savedDoc == null) {
return;
}
if (!accountingDocument.getSourceAccountingLines().isEmpty()) {
Map<Integer, AccountingLine> newSourceLines = buildAccountingLineMap(accountingDocument.getSourceAccountingLines());
Map<Integer, AccountingLine> savedSourceLines = buildAccountingLineMap(savedDoc.getSourceAccountingLines());
if (newSourceLines.isEmpty())
return;
int maxSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, false);
int minSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, true);
for (int i = minSourceKey; i < maxSourceKey + 1; i++) {
AccountingLine newLine = newSourceLines.get(i);
AccountingLine oldLine = savedSourceLines.get(i);
if (!compareTo(newLine, oldLine)) {
String diff = buildLineChangedNoteText(newLine, oldLine);
if (StringUtils.isNotBlank(diff)) {
writeNote(accountingDocument, diff);
}
}
}
}
if (!accountingDocument.getTargetAccountingLines().isEmpty()) {
Map<Integer, AccountingLine> newTargetLines = buildAccountingLineMap(accountingDocument.getTargetAccountingLines());
Map<Integer, AccountingLine> savedTargetLines = buildAccountingLineMap(savedDoc.getTargetAccountingLines());
if (newTargetLines.isEmpty())
return;
int maxTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, false);
int minTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, true);
for (int i = minTargetKey; i < maxTargetKey + 1; i++) {
AccountingLine newLine = newTargetLines.get(i);
AccountingLine oldLine = savedTargetLines.get(i);
if (!compareTo(newLine, oldLine)) {
String diff = buildLineChangedNoteText(newLine, oldLine);
if (StringUtils.isNotBlank(diff)) {
writeNote(accountingDocument, diff);
}
}
}
}
}
use of org.kuali.kfs.krad.service.DocumentService 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.service.DocumentService in project cu-kfs by CU-CommunityApps.
the class CheckReconciliationMaintainableImpl method doRouteStatusChange.
/**
* @see org.kuali.kfs.kns.maintenance.KualiMaintainableImpl#doRouteStatusChange(org.kuali.kfs.kns.bo.DocumentHeader)
*/
public void doRouteStatusChange(DocumentHeader documentHeader) {
WorkflowDocument workflowDocument = documentHeader.getWorkflowDocument();
if (workflowDocument.isProcessed() && !KFSConstants.MAINTENANCE_NEW_ACTION.equalsIgnoreCase(getMaintenanceAction())) {
DocumentService documentService = SpringContext.getBean(DocumentService.class);
MaintenanceDocument document;
try {
document = (MaintenanceDocument) documentService.getByDocumentHeaderId(documentHeader.getDocumentNumber());
CheckReconciliation oldCr = (CheckReconciliation) document.getOldMaintainableObject().getBusinessObject();
CheckReconciliation newCr = (CheckReconciliation) document.getNewMaintainableObject().getBusinessObject();
if (ObjectUtils.isNotNull(oldCr) && !oldCr.getStatus().equalsIgnoreCase(newCr.getStatus())) {
Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
newCr.setStatusChangeDate(currentDate);
// KFSUPGRADE-377
if (CRConstants.CANCELLED.equalsIgnoreCase(newCr.getStatus())) {
newCr.setCancelDocHdrId(documentHeader.getDocumentNumber());
}
}
} catch (WorkflowException e) {
throw new RuntimeCacheException(e);
}
}
}
use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method routeEIRTDocuments.
protected boolean routeEIRTDocuments() {
Collection<String> documentIdList = null;
try {
documentIdList = retrieveDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD, ElectronicInvoiceRejectDocument.class);
} catch (WorkflowException e1) {
LOG.error("Error retrieving eirt documents for routing: " + e1.getMessage(), e1);
throw new RuntimeException(e1.getMessage(), e1);
} catch (RemoteException re) {
LOG.error("Error retrieving eirt documents for routing: " + re.getMessage(), re);
throw new RuntimeException(re.getMessage(), re);
}
// Collections.reverse(documentIdList);
LOG.info("EIRTs to Route: " + documentIdList);
DocumentService documentService = SpringContext.getBean(DocumentService.class);
WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
for (String eirtDocumentId : documentIdList) {
try {
LOG.info("Retrieving EIRT document # " + eirtDocumentId + ".");
ElectronicInvoiceRejectDocument eirtDocument = (ElectronicInvoiceRejectDocument) documentService.getByDocumentHeaderId(eirtDocumentId);
LOG.info("Routing EIRT document # " + eirtDocumentId + ".");
documentService.prepareWorkflowDocument(eirtDocument);
LOG.info("EIRT document # " + eirtDocumentId + " prepared for workflow.");
// calling workflow service to bypass business rule checks
workflowDocumentService.route(eirtDocument.getDocumentHeader().getWorkflowDocument(), "Routed by electronic invoice batch job", null);
LOG.info("EIRT document # " + eirtDocumentId + " routed.");
} catch (WorkflowException e) {
LOG.error("Error routing document # " + eirtDocumentId + " " + e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}
return true;
}
Aggregations