001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.module.ld.businessobject.options; 017 018 import java.math.BigDecimal; 019 import java.text.ParseException; 020 import java.text.SimpleDateFormat; 021 import java.util.ArrayList; 022 import java.util.Date; 023 import java.util.Iterator; 024 import java.util.List; 025 026 import org.apache.commons.lang.StringUtils; 027 import org.kuali.kfs.module.ld.LaborPropertyConstants; 028 import org.kuali.kfs.sys.KFSPropertyConstants; 029 import org.kuali.rice.core.util.KeyLabelPair; 030 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase; 031 import org.kuali.rice.kns.util.KualiDecimal; 032 033 /** 034 * Field Finder for Labor Origin Entry. 035 */ 036 public class LaborOriginEntryFieldFinder extends KeyValuesBase { 037 038 /** 039 * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues() 040 */ 041 public List getKeyValues() { 042 List activeLabels = new ArrayList(); 043 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, "Fiscal Year")); 044 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, "Chart Code")); 045 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.ACCOUNT_NUMBER, "Account Number")); 046 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, "Sub-Account Number")); 047 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, "Object Code")); 048 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, "Sub-Object Code")); 049 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, "Balance Type")); 050 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE, "Object Type")); 051 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, "Fiscal Period")); 052 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, "Document Type")); 053 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE, "Origin code")); 054 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.DOCUMENT_NUMBER, "Document Number")); 055 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER, "Sequence Number")); 056 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.POSITION_NUMBER, "Position Number")); 057 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.PROJECT_CODE, "Project Code")); 058 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC, "Description")); 059 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT, "Amount")); 060 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, "Debit Credit Indicator")); 061 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_DATE, "Transaction Date")); 062 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER, "Org Doc Number")); 063 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID, "Org Ref ID")); 064 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE, "Ref Doc Type")); 065 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE, "Ref Origin code")); 066 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR, "Ref Doc Number")); 067 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE, "Reversal Date")); 068 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD, "Enc Update Code")); 069 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_POSTING_DATE, "Transaction Posting Date")); 070 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.PAY_PERIOD_END_DATE, "Pay Period End Date")); 071 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS, "Trn Total Hours")); 072 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR, "Payroll EndDate Fiscal Year")); 073 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE, "Payroll EndDate Fiscal Period Code")); 074 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.EMPLID, "Empl Id")); 075 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.EMPLOYEE_RECORD, "Empl Record")); 076 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.EARN_CODE, "Earn Code")); 077 activeLabels.add(new KeyLabelPair(KFSPropertyConstants.PAY_GROUP, "Pay Group")); 078 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.SALARY_ADMINISTRATION_PLAN, "Salary Admin Plan")); 079 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.GRADE, "Grade")); 080 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.RUN_IDENTIFIER, "Run Id")); 081 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.LABORLEDGER_ORIGINAL_CHART_OF_ACCOUNTS_CODE, "Original Chart Code")); 082 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.LABORLEDGER_ORIGINAL_ACCOUNT_NUMBER, "Original Account Number")); 083 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.LABORLEDGER_ORIGINAL_SUB_ACCOUNT_NUMBER, "Original Sub-Account Numbere")); 084 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_OBJECT_CODE, "Original Object Code")); 085 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_SUB_OBJECT_CODE, "Original Sub-Object Code")); 086 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.HRMS_COMPANY, "Company")); 087 activeLabels.add(new KeyLabelPair(LaborPropertyConstants.SET_ID, "SetId")); 088 089 return activeLabels; 090 } 091 092 /** 093 * Get field display name. 094 * 095 * @param fieldName 096 * @return Returns the label 097 */ 098 public String getFieldDisplayName(String fieldName) { 099 for (Iterator iter = getKeyValues().iterator(); iter.hasNext();) { 100 KeyLabelPair klp = (KeyLabelPair) iter.next(); 101 if (klp.getKey().equals(fieldName)) { 102 return klp.getLabel(); 103 } 104 } 105 106 return "Error"; 107 } 108 109 /** 110 * Get field name 111 * 112 * @param fieldDisplayName 113 * @return Returns the key 114 */ 115 public String getFieldName(String fieldDisplayName) { 116 for (Iterator iter = getKeyValues().iterator(); iter.hasNext();) { 117 KeyLabelPair klp = (KeyLabelPair) iter.next(); 118 if (klp.getLabel().equals(fieldDisplayName)) { 119 return (String) klp.getKey(); 120 } 121 } 122 123 return "Error"; 124 } 125 126 /** 127 * Check each field for valid value. 128 * 129 * @param fieldName 130 * @param value 131 * @return Returns a boolean 132 */ 133 public boolean isValidValue(String fieldName, String value) { 134 if (StringUtils.isBlank(fieldName)) { 135 return false; 136 } 137 String fieldType = getFieldType(fieldName); 138 int fieldLength = getFieldLength(fieldName); 139 140 if (allowNull(fieldName) && (value == null || value.length() == 0)) { 141 return true; 142 } 143 if (!allowNull(fieldName) && (value == null || value.length() == 0)) { 144 return false; 145 } 146 if (value.length() > fieldLength) { 147 return false; 148 } 149 if ("BigDecimal".equals(fieldType)) { 150 try { 151 BigDecimal d = new BigDecimal(value); 152 return true; 153 } 154 catch (NumberFormatException nfe) { 155 return false; 156 } 157 } 158 if ("KualiDecimal".equals(fieldType)) { 159 try { 160 KualiDecimal d = new KualiDecimal(value); 161 return true; 162 } 163 catch (NumberFormatException nfe) { 164 return false; 165 } 166 } 167 else if ("Integer".equals(fieldType)) { 168 try { 169 Integer d = new Integer(value); 170 return true; 171 } 172 catch (NumberFormatException nfe) { 173 return false; 174 } 175 } 176 else if ("Date".equals(fieldType)) { 177 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 178 try { 179 Date d = df.parse(value); 180 return true; 181 } 182 catch (ParseException e) { 183 return false; 184 } 185 } 186 187 return true; 188 } 189 190 /** 191 * Get field type. 192 * 193 * @param fieldName 194 * @return Returns the fieldType 195 */ 196 public String getFieldType(String fieldName) { 197 if (fieldName.equals("universityFiscalYear")) { 198 return "Integer"; 199 } 200 if (fieldName.equals("transactionLedgerEntrySequenceNumber")) { 201 return "Integer"; 202 } 203 if (fieldName.equals("transactionLedgerEntryAmount")) { 204 return "KualiDecimal"; 205 } 206 if (fieldName.equals("transactionDate")) { 207 return "Date"; 208 } 209 if (fieldName.equals("financialDocumentReversalDate")) { 210 return "Date"; 211 } 212 if (fieldName.equals("transactionPostingDate")) { 213 return "Date"; 214 } 215 if (fieldName.equals("payPeriodEndDate")) { 216 return "Date"; 217 } 218 if (fieldName.equals("transactionTotalHours")) { 219 return "BigDecimal"; 220 } 221 if (fieldName.equals("payrollEndDateFiscalYear")) { 222 return "Integer"; 223 } 224 if (fieldName.equals("transactionEntryProcessedTimestamp")) { 225 return "Date"; 226 } 227 if (fieldName.equals("employeeRecord")) { 228 return "Integer"; 229 } 230 if (fieldName.equals("transactionDateTimeStamp")) { 231 return "Date"; 232 } 233 return "String"; 234 } 235 236 /** 237 * Check if field allows null value 238 * 239 * @param fieldName 240 * @return Returns a boolean 241 */ 242 public boolean allowNull(String fieldName) { 243 if (fieldName.equals("transactionLedgerEntryAmount")) { 244 return false; 245 } 246 return true; 247 } 248 249 /** 250 * Get length of field from fieldName 251 * 252 * @param fieldName 253 * @return Returns an int 254 */ 255 public int getFieldLength(String fieldName) { 256 if (fieldName.equals("universityFiscalYear")) { 257 return 4; 258 } 259 else if (fieldName.equals("transactionLedgerEntrySequenceNumber")) { 260 return 5; 261 } 262 else if (fieldName.equals("transactionLedgerEntryAmount")) { 263 return 20; 264 } 265 else if (fieldName.equals("transactionDate")) { 266 return 10; 267 } 268 else if (fieldName.equals("financialDocumentReversalDate")) { 269 return 10; 270 } 271 else if (fieldName.equals("chartOfAccountsCode")) { 272 return 2; 273 } 274 else if (fieldName.equals("accountNumber")) { 275 return 7; 276 } 277 else if (fieldName.equals("subAccountNumber")) { 278 return 5; 279 } 280 else if (fieldName.equals("financialObjectCode")) { 281 return 4; 282 } 283 else if (fieldName.equals("financialSubObjectCode")) { 284 return 3; 285 } 286 else if (fieldName.equals("financialBalanceTypeCode")) { 287 return 2; 288 } 289 else if (fieldName.equals("financialObjectTypeCode")) { 290 return 2; 291 } 292 else if (fieldName.equals("universityFiscalPeriodCode")) { 293 return 2; 294 } 295 else if (fieldName.equals("financialDocumentTypeCode")) { 296 return 4; 297 } 298 else if (fieldName.equals("financialSystemOriginationCode")) { 299 return 2; 300 } 301 else if (fieldName.equals(KFSPropertyConstants.DOCUMENT_NUMBER)) { 302 return 14; 303 } 304 else if (fieldName.equals("transactionLedgerEntryDescription")) { 305 return 40; 306 } 307 else if (fieldName.equals("transactionDebitCreditCode")) { 308 return 1; 309 } 310 else if (fieldName.equals("organizationDocumentNumber")) { 311 return 10; 312 } 313 else if (fieldName.equals("projectCode")) { 314 return 10; 315 } 316 else if (fieldName.equals("organizationReferenceId")) { 317 return 8; 318 } 319 else if (fieldName.equals("referenceFinancialDocumentTypeCode")) { 320 return 4; 321 } 322 else if (fieldName.equals("referenceFinancialSystemOriginationCode")) { 323 return 2; 324 } 325 else if (fieldName.equals("referenceFinancialDocumentNumber")) { 326 return 14; 327 } 328 else if (fieldName.equals("transactionEncumbranceUpdateCode")) { 329 return 1; 330 } 331 else if (fieldName.equals("positionNumber")) { 332 return 8; 333 } 334 else if (fieldName.equals("transactionPostingDate")) { 335 return 10; 336 } 337 else if (fieldName.equals("payPeriodEndDate")) { 338 return 10; 339 } 340 else if (fieldName.equals("transactionTotalHours")) { 341 return 22; 342 } 343 else if (fieldName.equals("payrollEndDateFiscalYear")) { 344 return 4; 345 } 346 else if (fieldName.equals("payrollEndDateFiscalPeriodCode")) { 347 return 2; 348 } 349 else if (fieldName.equals("emplid")) { 350 return 11; 351 } 352 else if (fieldName.equals("employeeRecord")) { 353 return 3; 354 } 355 else if (fieldName.equals("earnCode")) { 356 return 3; 357 } 358 else if (fieldName.equals("payGroup")) { 359 return 3; 360 } 361 else if (fieldName.equals("salaryAdministrationPlan")) { 362 return 4; 363 } 364 else if (fieldName.equals("grade")) { 365 return 3; 366 } 367 else if (fieldName.equals("runIdentifier")) { 368 return 10; 369 } 370 else if (fieldName.equals("laborLedgerOriginalChartOfAccountsCode")) { 371 return 2; 372 } 373 else if (fieldName.equals("laborLedgerOriginalAccountNumber")) { 374 return 7; 375 } 376 else if (fieldName.equals("laborLedgerOriginalSubAccountNumber")) { 377 return 5; 378 } 379 else if (fieldName.equals("laborLedgerOriginalFinancialObjectCode")) { 380 return 4; 381 } 382 else if (fieldName.equals("laborLedgerOriginalFinancialSubObjectCode")) { 383 return 3; 384 } 385 else if (fieldName.equals("hrmsCompany")) { 386 return 3; 387 } 388 else if (fieldName.equals("setid")) { 389 return 5; 390 } 391 392 return 0; 393 } 394 }