List of usage examples for java.util SortedMap containsKey
boolean containsKey(Object key);
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java
protected SortedMap<BudgetCategoryType, List<CostElement>> categorizeObjectCodesByCategory(Budget budget) { SortedMap<CostElement, List<ScaleTwoDecimal>> objectCodeTotals = budget.getObjectCodeTotals(); SortedMap<BudgetCategoryType, List<CostElement>> objectCodeListByBudgetCategoryType = new TreeMap<>(); for (CostElement objectCode : objectCodeTotals.keySet()) { objectCode.refreshReferenceObject("budgetCategory"); if (objectCode.getBudgetCategory() != null) { objectCode.getBudgetCategory().refreshReferenceObject("budgetCategoryType"); objectCode.setBudgetCategoryTypeCode(objectCode.getBudgetCategory().getBudgetCategoryTypeCode()); }//from ww w .ja v a 2 s .c om if (!objectCodeListByBudgetCategoryType .containsKey(objectCode.getBudgetCategory().getBudgetCategoryType())) { List<CostElement> filteredObjectCodes = filterObjectCodesByBudgetCategoryType( objectCodeTotals.keySet(), objectCode.getBudgetCategoryTypeCode()); objectCodeListByBudgetCategoryType.put(objectCode.getBudgetCategory().getBudgetCategoryType(), filteredObjectCodes); } } return objectCodeListByBudgetCategoryType; }
From source file:org.apache.hadoop.hbase.regionserver.transactional.TransactionalHLogManager.java
/** * @param reconstructionLog/* w ww . jav a2s . c om*/ * @param maxSeqID * @param reporter * @return map of batch updates * @throws UnsupportedEncodingException * @throws IOException */ public Map<Long, List<BatchUpdate>> getCommitsFromLog(final Path reconstructionLog, final long maxSeqID, final Progressable reporter) throws UnsupportedEncodingException, IOException { if (reconstructionLog == null || !fileSystem.exists(reconstructionLog)) { // Nothing to do. return null; } // Check its not empty. FileStatus[] stats = fileSystem.listStatus(reconstructionLog); if (stats == null || stats.length == 0) { LOG.warn("Passed reconstruction log " + reconstructionLog + " is zero-length"); return null; } SortedMap<Long, List<BatchUpdate>> pendingTransactionsById = new TreeMap<Long, List<BatchUpdate>>(); SortedMap<Long, List<BatchUpdate>> commitedTransactionsById = new TreeMap<Long, List<BatchUpdate>>(); Set<Long> abortedTransactions = new HashSet<Long>(); SequenceFile.Reader logReader = new SequenceFile.Reader(fileSystem, reconstructionLog, conf); try { HLogKey key = new HLogKey(); HLogEdit val = new HLogEdit(); long skippedEdits = 0; long totalEdits = 0; long startCount = 0; long writeCount = 0; long abortCount = 0; long commitCount = 0; // How many edits to apply before we send a progress report. int reportInterval = conf.getInt("hbase.hstore.report.interval.edits", 2000); while (logReader.next(key, val)) { LOG.debug("Processing edit: key: " + key.toString() + " val: " + val.toString()); if (key.getLogSeqNum() < maxSeqID) { skippedEdits++; continue; } // TODO: Change all below so we are not doing a getRow and getColumn // against a KeyValue. Each invocation creates a new instance. St.Ack. // Check this edit is for me. byte[] column = val.getKeyValue().getColumn(); Long transactionId = val.getTransactionId(); if (!val.isTransactionEntry() || HLog.isMetaColumn(column) || !Bytes.equals(key.getRegionName(), regionInfo.getRegionName())) { continue; } List<BatchUpdate> updates = pendingTransactionsById.get(transactionId); switch (val.getOperation()) { case START: if (updates != null || abortedTransactions.contains(transactionId) || commitedTransactionsById.containsKey(transactionId)) { LOG.error("Processing start for transaction: " + transactionId + ", but have already seen start message"); throw new IOException("Corrupted transaction log"); } updates = new LinkedList<BatchUpdate>(); pendingTransactionsById.put(transactionId, updates); startCount++; break; case WRITE: if (updates == null) { LOG.error("Processing edit for transaction: " + transactionId + ", but have not seen start message"); throw new IOException("Corrupted transaction log"); } BatchUpdate tranUpdate = new BatchUpdate(val.getKeyValue().getRow()); if (val.getKeyValue().getValue() != null) { tranUpdate.put(val.getKeyValue().getColumn(), val.getKeyValue().getValue()); } else { tranUpdate.delete(val.getKeyValue().getColumn()); } updates.add(tranUpdate); writeCount++; break; case ABORT: if (updates == null) { LOG.error("Processing abort for transaction: " + transactionId + ", but have not seen start message"); throw new IOException("Corrupted transaction log"); } abortedTransactions.add(transactionId); pendingTransactionsById.remove(transactionId); abortCount++; break; case COMMIT: if (updates == null) { LOG.error("Processing commit for transaction: " + transactionId + ", but have not seen start message"); throw new IOException("Corrupted transaction log"); } if (abortedTransactions.contains(transactionId)) { LOG.error("Processing commit for transaction: " + transactionId + ", but also have abort message"); throw new IOException("Corrupted transaction log"); } if (updates.size() == 0) { LOG.warn("Transaciton " + transactionId + " has no writes in log. "); } if (commitedTransactionsById.containsKey(transactionId)) { LOG.error("Processing commit for transaction: " + transactionId + ", but have already commited transaction with that id"); throw new IOException("Corrupted transaction log"); } pendingTransactionsById.remove(transactionId); commitedTransactionsById.put(transactionId, updates); commitCount++; } totalEdits++; if (reporter != null && (totalEdits % reportInterval) == 0) { reporter.progress(); } } if (LOG.isDebugEnabled()) { LOG.debug("Read " + totalEdits + " tranasctional operations (skipped " + skippedEdits + " because sequence id <= " + maxSeqID + "): " + startCount + " starts, " + writeCount + " writes, " + abortCount + " aborts, and " + commitCount + " commits."); } } finally { logReader.close(); } if (pendingTransactionsById.size() > 0) { LOG.info("Region log has " + pendingTransactionsById.size() + " unfinished transactions. Going to the transaction log to resolve"); throw new RuntimeException("Transaction log not yet implemented"); } return commitedTransactionsById; }
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java
/** * This method is to categorize line item calculated amounts based on rate type *//* ww w. java 2 s .c om*/ private SortedMap<RateType, QueryList<BudgetLineItemCalculatedAmount>> getBudgetSummaryUniqueRateTypeCalAmounts( List<BudgetLineItem> budgetLineItems, boolean personnelFlag, String personnelCategoryTypeCode) { SortedMap<RateType, QueryList<BudgetLineItemCalculatedAmount>> uniqueLineItemCalAmounts = new TreeMap<>(); for (BudgetLineItem budgetLineItem : budgetLineItems) { if ((personnelFlag && StringUtils.equals( budgetLineItem.getCostElementBO().getBudgetCategory().getBudgetCategoryTypeCode(), personnelCategoryTypeCode)) || (!personnelFlag && !StringUtils.equals( budgetLineItem.getCostElementBO().getBudgetCategory().getBudgetCategoryTypeCode(), personnelCategoryTypeCode))) { for (BudgetLineItemCalculatedAmount budgetLineItemCalculatedAmount : budgetLineItem .getBudgetLineItemCalculatedAmounts()) { RateType rateType = getRateType(budgetLineItemCalculatedAmount); if (!uniqueLineItemCalAmounts.containsKey(rateType)) { uniqueLineItemCalAmounts.put(rateType, new QueryList<>()); } uniqueLineItemCalAmounts.get(rateType).add(budgetLineItemCalculatedAmount); } } } return uniqueLineItemCalAmounts; }
From source file:org.kuali.kra.budget.calculator.BudgetCalculationServiceImpl.java
/** * //from w w w . ja v a 2s .c om * @see org.kuali.kra.budget.calculator.BudgetCalculationService#calculateBudgetTotals(org.kuali.kra.budget.core.Budget) */ @SuppressWarnings("unchecked") public void calculateBudgetTotals(Budget budget) { // do we need to cache the totals ? SortedMap<CostElement, List<BudgetDecimal>> objectCodeTotals = new TreeMap<CostElement, List<BudgetDecimal>>(); SortedMap<RateType, List<BudgetDecimal>> calculatedExpenseTotals = new TreeMap<RateType, List<BudgetDecimal>>(); for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) { List<CostElement> objectCodes = new ArrayList<CostElement>(); QueryList lineItemQueryList = new QueryList(); lineItemQueryList.addAll(budgetPeriod.getBudgetLineItems()); budgetPeriod.setExpenseTotal(BudgetDecimal.ZERO); // probably need to add '0' to the period that has no such object code or ratetype ? for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) { if (budgetLineItem.getCostElementBO() == null) { budgetLineItem.refreshReferenceObject("costElementBO"); } CostElement costElement = budgetLineItem.getCostElementBO(); if (!objectCodes.contains(costElement)) { objectCodes.add(costElement); Equals equalsCostElement = new Equals("costElement", budgetLineItem.getCostElement()); BudgetDecimal objectCodeTotalInThisPeriod = lineItemQueryList.sumObjects("lineItemCost", equalsCostElement); if (!objectCodeTotals.containsKey(costElement)) { // set up for all periods and put into map List<BudgetDecimal> periodTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodTotals.add(i, BudgetDecimal.ZERO); } objectCodeTotals.put(costElement, periodTotals); } objectCodeTotals.get(costElement).set(budgetPeriod.getBudgetPeriod() - 1, objectCodeTotalInThisPeriod); budgetPeriod.setExpenseTotal(budgetPeriod.getExpenseTotal().add(objectCodeTotalInThisPeriod)); } // get calculated expenses QueryList lineItemCalcAmtQueryList = new QueryList(); lineItemCalcAmtQueryList.addAll(budgetLineItem.getBudgetLineItemCalculatedAmounts()); List<RateType> rateTypes = new ArrayList<RateType>(); for (Object item : budgetLineItem.getBudgetLineItemCalculatedAmounts()) { BudgetLineItemCalculatedAmount budgetLineItemCalculatedAmount = (BudgetLineItemCalculatedAmount) item; // if (budgetLineItemCalculatedAmount.getRateType() == null) { // budgetLineItemCalculatedAmount.refreshReferenceObject("rateType"); // } RateType rateType = createRateType(budgetLineItemCalculatedAmount); if (!rateTypes.contains(rateType)) { rateTypes.add(rateType); Equals equalsRC = new Equals("rateClassCode", budgetLineItemCalculatedAmount.getRateClassCode()); Equals equalsRT = new Equals("rateTypeCode", budgetLineItemCalculatedAmount.getRateTypeCode()); And RCandRT = new And(equalsRC, equalsRT); BudgetDecimal rateTypeTotalInThisPeriod = lineItemCalcAmtQueryList .sumObjects("calculatedCost", RCandRT); if (!calculatedExpenseTotals.containsKey(rateType)) { List<BudgetDecimal> rateTypePeriodTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { rateTypePeriodTotals.add(i, BudgetDecimal.ZERO); } calculatedExpenseTotals.put(rateType, rateTypePeriodTotals); } calculatedExpenseTotals.get(rateType) .set(budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) calculatedExpenseTotals.get(rateType) .get(budgetPeriod.getBudgetPeriod() - 1)) .add(rateTypeTotalInThisPeriod)); budgetPeriod.setExpenseTotal(budgetPeriod.getExpenseTotal().add(rateTypeTotalInThisPeriod)); } } } } budget.setObjectCodeTotals(objectCodeTotals); budget.setCalculatedExpenseTotals(calculatedExpenseTotals); }
From source file:org.neo4j.gis.spatial.OsmAnalysisTest.java
private SortedMap<String, Layer> exportPoints(String layerPrefix, SpatialDatabaseService spatialService, Set<User> users) {// w ww. ja v a 2 s . co m SortedMap<String, Layer> layers = new TreeMap<String, Layer>(); int startYear = 2009; int endYear = 2011; for (int y = startYear; y <= endYear; y++) { for (int w = 1; w <= 52; w++) { if (y == 2011 && w == 36) { break; } String name = layerPrefix + "-" + y + "_"; if (w >= 10) name += w; else name += "0" + w; EditableLayerImpl layer = (EditableLayerImpl) spatialService.createLayer(name, WKBGeometryEncoder.class, EditableLayerImpl.class); layer.setExtraPropertyNames( new String[] { "user_id", "user_name", "year", "month", "dayOfMonth", "weekOfYear" }); // EditableLayerImpl layer = (EditableLayerImpl) // spatialService.getLayer(name); layers.put(name, layer); } } for (User user : users) { Node userNode = graphDb().getNodeById(user.id); System.out.println("analyzing user: " + userNode.getProperty("name")); for (Relationship r : userNode.getRelationships(Direction.INCOMING, OSMRelation.USER)) { Node changeset = r.getStartNode(); if (changeset.hasProperty("changeset")) { System.out.println("analyzing changeset: " + changeset.getProperty("changeset")); try (Transaction tx = graphDb().beginTx()) { for (Relationship nr : changeset.getRelationships(Direction.INCOMING, OSMRelation.CHANGESET)) { Node changedNode = nr.getStartNode(); if (changedNode.hasProperty("node_osm_id") && changedNode.hasProperty("timestamp")) { long timestamp = (Long) changedNode.getProperty("timestamp"); Calendar c = Calendar.getInstance(); c.setTimeInMillis(timestamp); int nodeYear = c.get(Calendar.YEAR); int nodeWeek = c.get(Calendar.WEEK_OF_YEAR); if (layers.containsKey(layerPrefix + "-" + nodeYear + "_" + nodeWeek)) { EditableLayer l = (EditableLayer) layers .get(layerPrefix + "-" + nodeYear + "_" + nodeWeek); l.add(l.getGeometryFactory() .createPoint(new Coordinate((Double) changedNode.getProperty("lon"), (Double) changedNode.getProperty("lat"))), new String[] { "user_id", "user_name", "year", "month", "dayOfMonth", "weekOfYear" }, new Object[] { user.internalId, user.name, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.WEEK_OF_YEAR) }); } } } tx.success(); } } } } return layers; }
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java
@Deprecated protected void calculateBudgetTotals(Budget budget) { // do we need to cache the totals ? SortedMap<CostElement, List<ScaleTwoDecimal>> objectCodeTotals = new TreeMap<>(); SortedMap<RateType, List<ScaleTwoDecimal>> calculatedExpenseTotals = new TreeMap<>(); for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) { List<CostElement> objectCodes = new ArrayList<>(); QueryList<BudgetLineItem> lineItemQueryList = new QueryList<>(); lineItemQueryList.addAll(budgetPeriod.getBudgetLineItems()); budgetPeriod.setExpenseTotal(ScaleTwoDecimal.ZERO); // probably need to add '0' to the period that has no such object code or ratetype ? for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) { if (budgetLineItem.getCostElementBO() == null) { budgetLineItem.refreshReferenceObject("costElementBO"); }//from www . jav a 2 s. c om CostElement costElement = budgetLineItem.getCostElementBO(); if (!objectCodes.contains(costElement)) { objectCodes.add(costElement); Equals equalsCostElement = new Equals("costElement", budgetLineItem.getCostElement()); ScaleTwoDecimal objectCodeTotalInThisPeriod = lineItemQueryList.sumObjects("lineItemCost", equalsCostElement); if (!objectCodeTotals.containsKey(costElement)) { // set up for all periods and put into map List<ScaleTwoDecimal> periodTotals = new ArrayList<>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodTotals.add(i, ScaleTwoDecimal.ZERO); } objectCodeTotals.put(costElement, periodTotals); } objectCodeTotals.get(costElement).set(budgetPeriod.getBudgetPeriod() - 1, objectCodeTotalInThisPeriod); budgetPeriod.setExpenseTotal(budgetPeriod.getExpenseTotal().add(objectCodeTotalInThisPeriod)); } // get calculated expenses QueryList<BudgetLineItemCalculatedAmount> lineItemCalcAmtQueryList = new QueryList<>(); lineItemCalcAmtQueryList.addAll(budgetLineItem.getBudgetLineItemCalculatedAmounts()); List<RateType> rateTypes = new ArrayList<>(); for (Object item : budgetLineItem.getBudgetLineItemCalculatedAmounts()) { BudgetLineItemCalculatedAmount budgetLineItemCalculatedAmount = (BudgetLineItemCalculatedAmount) item; RateType rateType = createRateType(budgetLineItemCalculatedAmount); if (!rateTypes.contains(rateType)) { rateTypes.add(rateType); Equals equalsRC = new Equals("rateClassCode", budgetLineItemCalculatedAmount.getRateClassCode()); Equals equalsRT = new Equals("rateTypeCode", budgetLineItemCalculatedAmount.getRateTypeCode()); And RCandRT = new And(equalsRC, equalsRT); ScaleTwoDecimal rateTypeTotalInThisPeriod = lineItemCalcAmtQueryList .sumObjects(CALCULATED_COST, RCandRT); if (!calculatedExpenseTotals.containsKey(rateType)) { List<ScaleTwoDecimal> rateTypePeriodTotals = new ArrayList<>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { rateTypePeriodTotals.add(i, ScaleTwoDecimal.ZERO); } calculatedExpenseTotals.put(rateType, rateTypePeriodTotals); } calculatedExpenseTotals.get(rateType).set(budgetPeriod.getBudgetPeriod() - 1, (calculatedExpenseTotals.get(rateType).get(budgetPeriod.getBudgetPeriod() - 1)) .add(rateTypeTotalInThisPeriod)); budgetPeriod.setExpenseTotal(budgetPeriod.getExpenseTotal().add(rateTypeTotalInThisPeriod)); } } } } budget.setObjectCodeTotals(objectCodeTotals); budget.setCalculatedExpenseTotals(calculatedExpenseTotals); }
From source file:org.apache.hadoop.hbase.tool.LoadIncrementalHFiles.java
/** * If the table is created for the first time, then "completebulkload" reads the files twice. More * modifications necessary if we want to avoid doing it. *//*from ww w . j ava 2s. c o m*/ private void createTable(TableName tableName, Path hfofDir, Admin admin) throws IOException { final FileSystem fs = hfofDir.getFileSystem(getConf()); // Add column families // Build a set of keys List<ColumnFamilyDescriptorBuilder> familyBuilders = new ArrayList<>(); SortedMap<byte[], Integer> map = new TreeMap<>(Bytes.BYTES_COMPARATOR); visitBulkHFiles(fs, hfofDir, new BulkHFileVisitor<ColumnFamilyDescriptorBuilder>() { @Override public ColumnFamilyDescriptorBuilder bulkFamily(byte[] familyName) { ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder.newBuilder(familyName); familyBuilders.add(builder); return builder; } @Override public void bulkHFile(ColumnFamilyDescriptorBuilder builder, FileStatus hfileStatus) throws IOException { Path hfile = hfileStatus.getPath(); try (HFile.Reader reader = HFile.createReader(fs, hfile, CacheConfig.DISABLED, true, getConf())) { if (builder.getCompressionType() != reader.getFileContext().getCompression()) { builder.setCompressionType(reader.getFileContext().getCompression()); LOG.info("Setting compression " + reader.getFileContext().getCompression().name() + " for family " + builder.getNameAsString()); } reader.loadFileInfo(); byte[] first = reader.getFirstRowKey().get(); byte[] last = reader.getLastRowKey().get(); LOG.info("Trying to figure out region boundaries hfile=" + hfile + " first=" + Bytes.toStringBinary(first) + " last=" + Bytes.toStringBinary(last)); // To eventually infer start key-end key boundaries Integer value = map.containsKey(first) ? map.get(first) : 0; map.put(first, value + 1); value = map.containsKey(last) ? map.get(last) : 0; map.put(last, value - 1); } } }); byte[][] keys = inferBoundaries(map); TableDescriptorBuilder tdBuilder = TableDescriptorBuilder.newBuilder(tableName); familyBuilders.stream().map(ColumnFamilyDescriptorBuilder::build) .forEachOrdered(tdBuilder::setColumnFamily); admin.createTable(tdBuilder.build(), keys); LOG.info("Table " + tableName + " is available!!"); }
From source file:org.kuali.kfs.module.cam.batch.service.impl.AssetDepreciationServiceImpl.java
protected void populateYearEndDepreciationTransaction(AssetPaymentInfo assetPayment, String transactionType, String plantCOA, String plantAccount, ObjectCode deprObjectCode, SortedMap<String, AssetDepreciationTransaction> depreciationTransactionSummary) { LOG.info("\npopulateYearEndDepreciationTransaction - Asset#:" + assetPayment.getCapitalAssetNumber() + " amount:" + assetPayment.getTransactionAmount() + " type:" + transactionType); LOG.info("deprObjectCode.getFinancialObjectCode():" + deprObjectCode.getFinancialObjectCode() + " deprObjectCode.getFinancialObjectTypeCode():" + deprObjectCode.getFinancialObjectTypeCode()); AssetDepreciationTransaction depreciationTransaction = new AssetDepreciationTransaction(); depreciationTransaction.setCapitalAssetNumber(assetPayment.getCapitalAssetNumber()); depreciationTransaction.setChartOfAccountsCode(plantCOA); depreciationTransaction.setAccountNumber(plantAccount); depreciationTransaction.setSubAccountNumber(assetPayment.getSubAccountNumber()); depreciationTransaction.setFinancialObjectCode(deprObjectCode.getFinancialObjectCode()); depreciationTransaction.setFinancialSubObjectCode(assetPayment.getFinancialSubObjectCode()); depreciationTransaction.setFinancialObjectTypeCode(deprObjectCode.getFinancialObjectTypeCode()); depreciationTransaction.setTransactionType(transactionType); depreciationTransaction.setProjectCode(assetPayment.getProjectCode()); depreciationTransaction.setTransactionAmount(assetPayment.getTransactionAmount()); depreciationTransaction.setTransactionLedgerEntryDescription( "Year End Depreciation Asset " + assetPayment.getCapitalAssetNumber()); String sKey = depreciationTransaction.getKey(); // Grouping the asset transactions by asset#, accounts, sub account, object, transaction type (C/D), etc. in order to // only have one credit and one credit by group. if (depreciationTransactionSummary.containsKey(sKey)) { LOG.info("depreciationTransactionSummary.containsKey(sKey) where sKey=" + sKey); depreciationTransaction = depreciationTransactionSummary.get(sKey); depreciationTransaction.setTransactionAmount( depreciationTransaction.getTransactionAmount().add(assetPayment.getTransactionAmount())); } else {/*from w w w.ja va 2s.c om*/ LOG.info("depreciationTransactionSummary DOESNT containsKey(sKey) where sKey=" + sKey); depreciationTransactionSummary.put(sKey, depreciationTransaction); } LOG.info("\n\n"); // LOG.info("populateYearEndDepreciationTransaction(AssetDepreciationTransaction depreciationTransaction, AssetPayment assetPayment, String transactionType, KualiDecimal transactionAmount, String plantCOA, String plantAccount, String accumulatedDepreciationFinancialObjectCode, String depreciationExpenseFinancialObjectCode, ObjectCode financialObject, SortedMap<String, AssetDepreciationTransaction> depreciationTransactionSummary) - ended"); }
From source file:org.slc.sli.dashboard.manager.impl.StudentProgressManagerImpl.java
@Override @SuppressWarnings("unchecked") @LogExecutionTime//from w ww . java 2 s .co m public GenericEntity getTranscript(String token, Object studentIdObj, Config.Data config) { SortedMap<GenericEntity, List<GenericEntity>> transcripts = new TreeMap<GenericEntity, List<GenericEntity>>( new SessionComparator()); String studentId = studentIdObj.toString(); List<String> optionalFields = new LinkedList<String>(); optionalFields.add(Constants.ATTR_TRANSCRIPT); GenericEntity studentWithTranscript = entityManager.getStudentWithOptionalFields(token, studentId, optionalFields); if (studentWithTranscript == null) { return new GenericEntity(); } Map<String, Object> studentTranscript = (Map<String, Object>) studentWithTranscript .get(Constants.ATTR_TRANSCRIPT); if (studentTranscript == null) { return new GenericEntity(); } List<Map<String, Object>> courseTranscripts = (List<Map<String, Object>>) studentTranscript .get(Constants.ATTR_COURSE_TRANSCRIPTS); List<Map<String, Object>> studentSectionAssociations = (List<Map<String, Object>>) studentTranscript .get(Constants.ATTR_STUDENT_SECTION_ASSOC); if (studentSectionAssociations == null || courseTranscripts == null) { return new GenericEntity(); } Map<String, GenericEntity> cache = new HashMap<String, GenericEntity>(); cacheStudent(studentId, token, studentSectionAssociations, cache, courseTranscripts); for (Map<String, Object> studentSectionAssociation : studentSectionAssociations) { Map<String, Object> courseTranscript = getCourseTranscriptForSection(studentSectionAssociation, courseTranscripts); // skip this course if we can't find previous info if (courseTranscript == null) { continue; } Map<String, Object> section = getGenericEntity(studentSectionAssociation, Constants.ATTR_SECTIONS); Map<String, Object> course = getGenericEntity(section, Constants.ATTR_COURSES); Map<String, Object> session = getGenericEntity(section, Constants.ATTR_SESSIONS); GenericEntity term = new GenericEntity(); term.put(Constants.ATTR_TERM, getValue(session, Constants.ATTR_TERM)); term.put(Constants.ATTR_GRADE_LEVEL, getValue(courseTranscript, Constants.ATTR_GRADE_LEVEL_WHEN_TAKEN)); term.put(Constants.ATTR_SCHOOL, getSchoolName(section, token, cache)); term.put(Constants.ATTR_SCHOOL_YEAR, getValue(session, Constants.ATTR_SCHOOL_YEAR)); term.put(Constants.ATTR_CUMULATIVE_GPA, getGPA(session, studentId, token, cache)); term.put(Constants.ATTR_SESSION_BEGIN_DATE, getValue(session, Constants.ATTR_SESSION_BEGIN_DATE)); GenericEntityEnhancer.convertGradeLevel(term, Constants.ATTR_GRADE_LEVEL); // This isn't a new term if (transcripts.containsKey(term)) { List<GenericEntity> courses = transcripts.get(term); GenericEntity courseData = getCourseData(courseTranscript, course); courses.add(courseData); } else { // this is the first time the term has been encountered List<GenericEntity> courses = new ArrayList<GenericEntity>(); GenericEntity courseData = getCourseData(courseTranscript, course); courses.add(courseData); transcripts.put(term, courses); } } List<GenericEntity> transcriptData = new ArrayList<GenericEntity>(); for (Map.Entry<GenericEntity, List<GenericEntity>> entry : transcripts.entrySet()) { GenericEntity term = new GenericEntity(); term.putAll(entry.getKey()); term.put(Constants.ATTR_COURSES, entry.getValue()); transcriptData.add(term); } GenericEntity ret = new GenericEntity(); ret.put(TRANSCRIPT_HISTORY, transcriptData); return ret; }
From source file:org.kuali.kra.budget.calculator.BudgetCalculationServiceImpl.java
public void calculateBudgetSummaryTotals(Budget budget) { calculateBudgetTotals(budget);/* w w w . j ava 2 s . c o m*/ //Categorize all Object Codes per their Category Type SortedMap<BudgetCategoryType, List<CostElement>> objectCodeListByBudgetCategoryType = categorizeObjectCodesByCategory( budget); SortedMap<CostElement, List<BudgetPersonnelDetails>> objectCodeUniquePersonnelList = new TreeMap<CostElement, List<BudgetPersonnelDetails>>(); SortedMap<String, List<BudgetDecimal>> objectCodePersonnelSalaryTotals = new TreeMap<String, List<BudgetDecimal>>(); SortedMap<String, List<BudgetDecimal>> objectCodePersonnelFringeTotals = new TreeMap<String, List<BudgetDecimal>>(); //Temp collections for maintaining Sub Section Totals SortedSet<String> objectCodePersonnelSalaryTotalsByPeriod = new TreeSet<String>(); SortedSet<String> objectCodePersonnelFringeTotalsByPeriod = new TreeSet<String>(); SortedMap<RateType, List<BudgetDecimal>> personnelCalculatedExpenseTotals = new TreeMap<RateType, List<BudgetDecimal>>(); SortedMap<RateType, List<BudgetDecimal>> nonPersonnelCalculatedExpenseTotals = new TreeMap<RateType, List<BudgetDecimal>>(); List<BudgetDecimal> periodSummarySalaryTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodSummarySalaryTotals.add(i, BudgetDecimal.ZERO); } List<BudgetDecimal> periodSummaryFringeTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodSummaryFringeTotals.add(i, BudgetDecimal.ZERO); } SortedMap<String, List<BudgetDecimal>> subTotalsBySubSection = new TreeMap<String, List<BudgetDecimal>>(); subTotalsBySubSection.put("personnelSalaryTotals", periodSummarySalaryTotals); subTotalsBySubSection.put("personnelFringeTotals", periodSummaryFringeTotals); //Loop thru the Personnel Object Codes - to calculate Salary, Fringe Totals etc.. per person BudgetCategoryType personnelCategory = getPersonnelCategoryType(); List<CostElement> personnelObjectCodes = objectCodeListByBudgetCategoryType.get(personnelCategory); if (CollectionUtils.isNotEmpty(personnelObjectCodes)) { for (CostElement personnelCostElement : personnelObjectCodes) { if (!objectCodeUniquePersonnelList.containsKey(personnelCostElement)) { objectCodeUniquePersonnelList.put(personnelCostElement, new ArrayList<BudgetPersonnelDetails>()); } for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) { budgetPeriod.setBudget(budget); QueryList lineItemQueryList = new QueryList(); lineItemQueryList.addAll(budgetPeriod.getBudgetLineItems()); Equals objectCodeEquals = new Equals("costElement", personnelCostElement.getCostElement()); QueryList<BudgetLineItem> filteredLineItems = lineItemQueryList.filter(objectCodeEquals); QueryList personnelQueryList = new QueryList(); //Loop thru the matching Line Items to gather personnel info for (BudgetLineItem matchingLineItem : filteredLineItems) { personnelQueryList.addAll(matchingLineItem.getBudgetPersonnelDetailsList()); } int matchingLineItemIndex = 0; for (BudgetLineItem matchingLineItem : filteredLineItems) { for (BudgetPersonnelDetails budgetPersonnelDetails : matchingLineItem .getBudgetPersonnelDetailsList()) { budgetPersonnelDetails.refreshReferenceObject("budgetPerson"); Equals personIdEquals = new Equals("personId", budgetPersonnelDetails.getPersonId()); QueryList personOccurrencesForSameObjectCode = personnelQueryList .filter(personIdEquals); //Calculate the Salary Totals for each Person BudgetDecimal personSalaryTotalsForCurrentPeriod = personOccurrencesForSameObjectCode .sumObjects("salaryRequested"); if (!objectCodePersonnelSalaryTotals.containsKey(matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId())) { objectCodeUniquePersonnelList.get(matchingLineItem.getCostElementBO()) .add(budgetPersonnelDetails); // set up for all periods and put into map List<BudgetDecimal> periodTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodTotals.add(i, BudgetDecimal.ZERO); } objectCodePersonnelSalaryTotals.put(matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId(), periodTotals); } //Setting the total lines here - so that they'll be set just once for a unique person within an Object Code objectCodePersonnelSalaryTotals .get(matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId()) .set(budgetPeriod.getBudgetPeriod() - 1, personSalaryTotalsForCurrentPeriod); //subTotalsBySubSection.get("personnelSalaryTotals").set(budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) (subTotalsBySubSection.get("personnelSalaryTotals").get(budgetPeriod.getBudgetPeriod() - 1))).add(personSalaryTotalsForCurrentPeriod)); if (objectCodePersonnelSalaryTotalsByPeriod .add(budgetPeriod.getBudgetPeriod().toString() + "," + matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId())) { subTotalsBySubSection.get("personnelSalaryTotals").set( budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) (subTotalsBySubSection.get("personnelSalaryTotals") .get(budgetPeriod.getBudgetPeriod() - 1))) .add(personSalaryTotalsForCurrentPeriod)); } //Calculate the Fringe Totals for each Person if (!objectCodePersonnelFringeTotals.containsKey(matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId())) { // set up for all periods and put into map List<BudgetDecimal> periodFringeTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodFringeTotals.add(i, BudgetDecimal.ZERO); } objectCodePersonnelFringeTotals.put(matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId(), periodFringeTotals); } BudgetDecimal personFringeTotalsForCurrentPeriod = BudgetDecimal.ZERO; // if(!isSummaryCalcAmountChanged(budget,budgetPeriod)){ //Calculate the Fringe Totals for that Person (cumulative fringe for all occurrences of the person) for (Object person : personOccurrencesForSameObjectCode) { BudgetPersonnelDetails personOccurrence = (BudgetPersonnelDetails) person; for (BudgetPersonnelCalculatedAmount calcExpenseAmount : personOccurrence .getBudgetPersonnelCalculatedAmounts()) { calcExpenseAmount.refreshReferenceObject("rateClass"); //Check for Employee Benefits RateClassType if (calcExpenseAmount.getRateClass().getRateClassType().equalsIgnoreCase("E")) { personFringeTotalsForCurrentPeriod = personFringeTotalsForCurrentPeriod .add(calcExpenseAmount.getCalculatedCost()); } } } objectCodePersonnelFringeTotals .get(matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId()) .set(budgetPeriod.getBudgetPeriod() - 1, personFringeTotalsForCurrentPeriod); //subTotalsBySubSection.get("personnelFringeTotals").set(budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) (subTotalsBySubSection.get("personnelFringeTotals").get(budgetPeriod.getBudgetPeriod() - 1))).add(personFringeTotalsForCurrentPeriod)); // } if (objectCodePersonnelFringeTotalsByPeriod .add(budgetPeriod.getBudgetPeriod().toString() + "," + matchingLineItem.getCostElement() + "," + budgetPersonnelDetails.getPersonId())) { subTotalsBySubSection.get("personnelFringeTotals").set( budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) (subTotalsBySubSection.get("personnelFringeTotals") .get(budgetPeriod.getBudgetPeriod() - 1))) .add(personFringeTotalsForCurrentPeriod)); } } //Need to handle the Summary Items - if any if (CollectionUtils.isEmpty(matchingLineItem.getBudgetPersonnelDetailsList())) { //Include Summary Item Salary (Line Item Cost) if (!objectCodePersonnelSalaryTotals.containsKey(matchingLineItem.getCostElement())) { // set up for all periods and put into map List<BudgetDecimal> periodTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodTotals.add(i, BudgetDecimal.ZERO); } objectCodePersonnelSalaryTotals.put(matchingLineItem.getCostElement(), periodTotals); } objectCodePersonnelSalaryTotals.get(matchingLineItem.getCostElement()).set( budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) objectCodePersonnelSalaryTotals .get(matchingLineItem.getCostElement()) .get(budgetPeriod.getBudgetPeriod() - 1)) .add(matchingLineItem.getLineItemCost())); //Include Summary Item Fringe Amt BudgetDecimal summaryFringeTotalsForCurrentPeriod = BudgetDecimal.ZERO; if (!objectCodePersonnelFringeTotals.containsKey(matchingLineItem.getCostElement())) { // set up for all periods and put into map List<BudgetDecimal> periodFringeTotals = new ArrayList<BudgetDecimal>(); for (int i = 0; i < budget.getBudgetPeriods().size(); i++) { periodFringeTotals.add(i, BudgetDecimal.ZERO); } objectCodePersonnelFringeTotals.put(matchingLineItem.getCostElement(), periodFringeTotals); } for (BudgetLineItemCalculatedAmount lineItemCalculatedAmount : matchingLineItem .getBudgetLineItemCalculatedAmounts()) { lineItemCalculatedAmount.refreshReferenceObject("rateClass"); //Check for Employee Benefits RateClassType if (lineItemCalculatedAmount.getRateClass().getRateClassType() .equalsIgnoreCase("E")) { summaryFringeTotalsForCurrentPeriod = summaryFringeTotalsForCurrentPeriod .add(lineItemCalculatedAmount.getCalculatedCost()); } } objectCodePersonnelFringeTotals.get(matchingLineItem.getCostElement()).set( budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) objectCodePersonnelFringeTotals .get(matchingLineItem.getCostElement()) .get(budgetPeriod.getBudgetPeriod() - 1)) .add(summaryFringeTotalsForCurrentPeriod)); //if(matchingLineItemIndex == filteredLineItems.size()-1) { subTotalsBySubSection.get("personnelSalaryTotals").set( budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) (subTotalsBySubSection.get("personnelSalaryTotals") .get(budgetPeriod.getBudgetPeriod() - 1))) .add((BudgetDecimal) (objectCodePersonnelSalaryTotals .get(matchingLineItem.getCostElement()) .get(budgetPeriod.getBudgetPeriod() - 1)))); subTotalsBySubSection.get("personnelFringeTotals").set( budgetPeriod.getBudgetPeriod() - 1, ((BudgetDecimal) (subTotalsBySubSection.get("personnelFringeTotals") .get(budgetPeriod.getBudgetPeriod() - 1))) .add((BudgetDecimal) (objectCodePersonnelFringeTotals .get(matchingLineItem.getCostElement()) .get(budgetPeriod.getBudgetPeriod() - 1)))); //} } matchingLineItemIndex++; } } //Budget Period Looping Ends here } //Personnel Object Code Looping Ends here } budget.setBudgetSummaryTotals(subTotalsBySubSection); personnelCalculatedExpenseTotals = calculateExpenseTotals(budget, true); nonPersonnelCalculatedExpenseTotals = calculateExpenseTotals(budget, false); budget.setObjectCodeListByBudgetCategoryType(objectCodeListByBudgetCategoryType); //budget.setObjectCodePersonnelList(objectCodePersonnelList); budget.setObjectCodePersonnelList(objectCodeUniquePersonnelList); budget.setObjectCodePersonnelSalaryTotals(objectCodePersonnelSalaryTotals); budget.setObjectCodePersonnelFringeTotals(objectCodePersonnelFringeTotals); budget.setPersonnelCalculatedExpenseTotals(personnelCalculatedExpenseTotals); budget.setNonPersonnelCalculatedExpenseTotals(nonPersonnelCalculatedExpenseTotals); calculateNonPersonnelSummaryTotals(budget); populateBudgetPeriodSummaryCalcAmounts(budget); }