Search in sources :

Example 1 with DataDictionaryService

use of org.kuali.kfs.krad.service.DataDictionaryService in project cu-kfs by CU-CommunityApps.

the class PayeeACHAccount method toString.

/**
 * KFSCNTRB-1682: Some of the fields contain confidential information
 *
 * @see org.kuali.rice.krad.bo.BusinessObjectBase#toString()
 */
@Override
public String toString() {
    class PayeeACHAccountToStringBuilder extends ReflectionToStringBuilder {

        private PayeeACHAccountToStringBuilder(Object object) {
            super(object);
        }

        @Override
        public boolean accept(Field field) {
            if (BusinessObject.class.isAssignableFrom(field.getType())) {
                return false;
            }
            DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
            AttributeSecurity attributeSecurity = dataDictionaryService.getAttributeSecurity(PayeeACHAccount.class.getName(), field.getName());
            if ((ObjectUtils.isNotNull(attributeSecurity) && (attributeSecurity.isHide() || attributeSecurity.isMask() || attributeSecurity.isPartialMask()))) {
                return false;
            }
            return super.accept(field);
        }
    }
    ;
    ReflectionToStringBuilder toStringBuilder = new PayeeACHAccountToStringBuilder(this);
    return toStringBuilder.toString();
}
Also used : Field(java.lang.reflect.Field) BusinessObject(org.kuali.rice.krad.bo.BusinessObject) ReflectionToStringBuilder(org.apache.commons.lang.builder.ReflectionToStringBuilder) DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService) AttributeSecurity(org.kuali.kfs.krad.datadictionary.AttributeSecurity)

Example 2 with DataDictionaryService

use of org.kuali.kfs.krad.service.DataDictionaryService in project cu-kfs by CU-CommunityApps.

the class CuBatchExtractServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    BusinessObjectService businessObjectService = buildMockBusinessObjectService();
    DataDictionaryService dataDictionaryService = buildMockDataDictionaryService();
    cuBatchExtractServiceImpl = new CuBatchExtractServiceImpl();
    cuBatchExtractServiceImpl.setBusinessObjectService(businessObjectService);
    cuBatchExtractServiceImpl.setDataDictionaryService(dataDictionaryService);
}
Also used : DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) Before(org.junit.Before)

Example 3 with DataDictionaryService

use of org.kuali.kfs.krad.service.DataDictionaryService in project cu-kfs by CU-CommunityApps.

the class ProcurementCardCreateDocumentServiceImpl method createProcurementCardDocument.

/**
 * Creates a ProcurementCardDocument from the List of transactions given.
 *
 * @param transactions List of ProcurementCardTransaction objects to be used for creating the document.
 * @return A ProcurementCardDocument populated with the transactions provided.
 */
@SuppressWarnings({ "rawtypes", "deprecation" })
@Override
public ProcurementCardDocument createProcurementCardDocument(List transactions) {
    ProcurementCardDocument pcardDocument = null;
    dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
    try {
        // get new document from doc service
        pcardDocument = buildNewProcurementCardDocument();
        List<CapitalAssetInformation> capitalAssets = pcardDocument.getCapitalAssetInformation();
        for (CapitalAssetInformation capitalAsset : capitalAssets) {
            if (ObjectUtils.isNotNull(capitalAsset) && ObjectUtils.isNotNull(capitalAsset.getCapitalAssetInformationDetails())) {
                capitalAsset.setDocumentNumber(pcardDocument.getDocumentNumber());
            }
        }
        ProcurementCardTransaction trans = (ProcurementCardTransaction) transactions.get(0);
        String errorText = validateTransaction(trans);
        createCardHolderRecord(pcardDocument, trans);
        // for each transaction, create transaction detail object and then acct lines for the detail
        int transactionLineNumber = 1;
        KualiDecimal documentTotalAmount = KualiDecimal.ZERO;
        ProcurementCardTransaction transaction = null;
        for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
            /*ProcurementCardTransaction*/
            transaction = (ProcurementCardTransaction) iter.next();
            // create transaction detail record with accounting lines
            errorText += createTransactionDetailRecord(pcardDocument, transaction, transactionLineNumber);
            // update document total
            documentTotalAmount = documentTotalAmount.add(transaction.getFinancialDocumentTotalAmount());
            transactionLineNumber++;
        }
        pcardDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(documentTotalAmount);
        // pcardDocument.getDocumentHeader().setDocumentDescription("SYSTEM Generated");
        transaction = (ProcurementCardTransaction) transactions.get(0);
        String cardHolderName = transaction.getCardHolderName();
        String vendorName = transaction.getVendorName();
        String transactionType = ((ProcurementCardTransactionExtendedAttribute) transaction.getExtension()).getTransactionType();
        if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
            VENDOR_NAME_MAX_LENGTH = 16;
        } else {
            VENDOR_NAME_MAX_LENGTH = 19;
        }
        if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() > VENDOR_NAME_MAX_LENGTH) {
            cardHolderName = cardHolderName.substring(0, CARD_HOLDER_MAX_LENGTH);
            vendorName = vendorName.substring(0, VENDOR_NAME_MAX_LENGTH);
        }
        if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() <= VENDOR_NAME_MAX_LENGTH) {
            Integer endIndice = 0;
            if ((CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length())) > cardHolderName.length()) {
                endIndice = cardHolderName.length();
            } else {
                endIndice = CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length());
            }
            cardHolderName = cardHolderName.substring(0, endIndice);
        }
        if (vendorName.length() > VENDOR_NAME_MAX_LENGTH && cardHolderName.length() <= CARD_HOLDER_MAX_LENGTH) {
            Integer endIndice = 0;
            if ((VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length())) > vendorName.length()) {
                endIndice = vendorName.length();
            } else {
                endIndice = VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length());
            }
            vendorName = vendorName.substring(0, endIndice);
        }
        String creditCardNumber = transaction.getTransactionCreditCardNumber();
        String lastFour = "";
        if (creditCardNumber.length() > CC_LAST_FOUR) {
            lastFour = creditCardNumber.substring(creditCardNumber.length() - CC_LAST_FOUR);
        }
        String docDesc = cardHolderName + "/" + vendorName + "/" + lastFour;
        if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
            docDesc = transactionType + "/" + cardHolderName + "/" + vendorName + "/" + lastFour;
        }
        if (docDesc.length() > MAX_DOC_DESC_LENGTH) {
            docDesc = docDesc.substring(0, MAX_DOC_DESC_LENGTH);
        }
        pcardDocument.getDocumentHeader().setDocumentDescription(docDesc);
        // Remove duplicate messages from errorText
        String[] messages = StringUtils.split(errorText, ".");
        for (int i = 0; i < messages.length; i++) {
            int countMatches = StringUtils.countMatches(errorText, messages[i]) - 1;
            errorText = StringUtils.replace(errorText, messages[i] + ".", "", countMatches);
        }
        // In case errorText is still too long, truncate it and indicate so.
        Integer documentExplanationMaxLength = dataDictionaryService.getAttributeMaxLength(DocumentHeader.class.getName(), KFSPropertyConstants.EXPLANATION);
        if (documentExplanationMaxLength != null && errorText.length() > documentExplanationMaxLength.intValue()) {
            String truncatedMessage = " ... TRUNCATED.";
            errorText = errorText.substring(0, documentExplanationMaxLength - truncatedMessage.length()) + truncatedMessage;
        }
        pcardDocument.getDocumentHeader().setExplanation(errorText);
    } catch (WorkflowException e) {
        LOG.error("Error creating pcdo documents: " + e.getMessage(), e);
        throw new RuntimeException("Error creating pcdo documents: " + e.getMessage(), e);
    }
    return pcardDocument;
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService) ProcurementCardDocument(org.kuali.kfs.fp.document.ProcurementCardDocument) ProcurementCardTransactionExtendedAttribute(edu.cornell.kfs.fp.businessobject.ProcurementCardTransactionExtendedAttribute) ProcurementCardTransaction(org.kuali.kfs.fp.businessobject.ProcurementCardTransaction) Iterator(java.util.Iterator) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 4 with DataDictionaryService

use of org.kuali.kfs.krad.service.DataDictionaryService in project cu-kfs by CU-CommunityApps.

the class PayeeACHAccountExtractServiceImplTest method createMockDataDictionaryService.

private DataDictionaryService createMockDataDictionaryService() throws Exception {
    /*
         * Only a few specific attribute definitions should be masked or have values finders; the rest
         * should be plain. Also, we only care about the max lengths of a few specific properties.
         */
    DataDictionaryService ddService = EasyMock.createMock(DataDictionaryServiceImpl.class);
    EasyMock.expect(ddService.getAttributeDefinition(EasyMock.eq(PayeeACHAccount.class.getName()), EasyMock.or(EasyMock.eq(BANK_ACCOUNT_NUMBER), EasyMock.eq(BANK_NAME)))).andStubReturn(createMaskedAttributeDefinition());
    EasyMock.expect(ddService.getAttributeDefinition(PayeeACHAccount.class.getName(), BANK_ACCOUNT_TYPE_CODE)).andStubReturn(createAttributeDefinitionWithValuesFinder(CUCheckingSavingsValuesFinder.class.getName(), true));
    EasyMock.expect(ddService.getAttributeDefinition(EasyMock.eq(PayeeACHAccount.class.getName()), EasyMock.and(EasyMock.not(EasyMock.eq(BANK_ACCOUNT_TYPE_CODE)), EasyMock.and(EasyMock.not(EasyMock.eq(BANK_ACCOUNT_NUMBER)), EasyMock.not(EasyMock.eq(BANK_NAME)))))).andStubReturn(createUnmaskedAttributeDefinition());
    EasyMock.expect(ddService.getAttributeMaxLength(DocumentHeader.class.getName(), KRADPropertyConstants.DOCUMENT_DESCRIPTION)).andStubReturn(DOCUMENT_DESCRIPTION_MAX_LENGTH);
    EasyMock.replay(ddService);
    return ddService;
}
Also used : PayeeACHAccount(org.kuali.kfs.pdp.businessobject.PayeeACHAccount) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService)

Example 5 with DataDictionaryService

use of org.kuali.kfs.krad.service.DataDictionaryService in project cu-kfs by CU-CommunityApps.

the class CuBatchExtractServiceImplTest method buildMockDataDictionaryService.

private DataDictionaryService buildMockDataDictionaryService() {
    DataDictionaryService dataDictionaryService = EasyMock.createMock(DataDictionaryService.class);
    expectDocumentClassMapping(dataDictionaryService, PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT, CuVendorCreditMemoDocument.class);
    expectDocumentClassMapping(dataDictionaryService, PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT, CuPaymentRequestDocument.class);
    EasyMock.replay(dataDictionaryService);
    return dataDictionaryService;
}
Also used : DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService)

Aggregations

DataDictionaryService (org.kuali.kfs.krad.service.DataDictionaryService)5 DocumentHeader (org.kuali.kfs.krad.bo.DocumentHeader)2 ProcurementCardTransactionExtendedAttribute (edu.cornell.kfs.fp.businessobject.ProcurementCardTransactionExtendedAttribute)1 Field (java.lang.reflect.Field)1 Iterator (java.util.Iterator)1 ReflectionToStringBuilder (org.apache.commons.lang.builder.ReflectionToStringBuilder)1 Before (org.junit.Before)1 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)1 ProcurementCardTransaction (org.kuali.kfs.fp.businessobject.ProcurementCardTransaction)1 ProcurementCardDocument (org.kuali.kfs.fp.document.ProcurementCardDocument)1 AttributeSecurity (org.kuali.kfs.krad.datadictionary.AttributeSecurity)1 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1 PayeeACHAccount (org.kuali.kfs.pdp.businessobject.PayeeACHAccount)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)1 BusinessObject (org.kuali.rice.krad.bo.BusinessObject)1