All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.capitalone.dashboard.service.RallyFeatureServiceImpl Maven / Gradle / Ivy

There is a newer version: 3.4.53
Show newest version
package com.capitalone.dashboard.service;

import com.capitalone.dashboard.model.Collector;
import com.capitalone.dashboard.model.CollectorItem;
import com.capitalone.dashboard.model.CollectorType;
import com.capitalone.dashboard.model.Component;
import com.capitalone.dashboard.model.RallyBurnDownData;
import com.capitalone.dashboard.model.RallyFeature;
import com.capitalone.dashboard.repository.CollectorRepository;
import com.capitalone.dashboard.repository.ComponentRepository;
import com.capitalone.dashboard.repository.RallyBurnDownRepository;
import com.capitalone.dashboard.repository.RallyFeatureRepository;
import com.capitalone.dashboard.request.RallyFeatureRequest;
import com.capitalone.dashboard.response.RallyBurnDownResponse;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

@Service
public class RallyFeatureServiceImpl implements RallyFeatureService {
	
	private final RallyFeatureRepository rallyFeatureRepository;
	private final RallyBurnDownRepository rallyBurnDownRepository;

	private final CollectorRepository collectorRepository;
	private final ComponentRepository componentRepository;

	@Autowired
	public RallyFeatureServiceImpl(RallyFeatureRepository rallyFeatureRepository,
			RallyBurnDownRepository rallyBurnDownRepository,
			CollectorRepository collectorRepository,
			ComponentRepository componentRepository) {
		this.rallyFeatureRepository = rallyFeatureRepository;
		this.rallyBurnDownRepository = rallyBurnDownRepository;
		this.collectorRepository = collectorRepository;
		this.componentRepository = componentRepository;
	}

	@Override
	public List rallyProjectIterationType(String projectId) {
		List iteraioncount = rallyFeatureRepository.findByIterationLists(projectId);
		Set s1 = new HashSet();
		for (int i = 0; i < iteraioncount.size(); i++) {
			s1.add(iteraioncount.get(i));
		}
		iteraioncount.clear();
		iteraioncount.addAll(s1);
		return iteraioncount;
	}

	public List rallyWidgetDataDetails(CollectorItem collectorItem) {
		List currentIteration = rallyFeatureRepository
				.findByCollectorItemIdAndRemainingDaysNot(collectorItem.getId(),0);
		return currentIteration;
	}

	
	public CollectorItem getCollectorItem(RallyFeatureRequest request) {
		Component component = componentRepository.findOne(request.getComponentId());
		if (component == null) {
			return null;
		}

		List collectorItems = component.getCollectorItems(CollectorType.AgileTool);
		ObjectId collectorId = null;
		Optional collector = collectorRepository.findByCollectorTypeAndName(CollectorType.AgileTool, "Rally")
															.stream()
															.findFirst();
		collectorId = collector.get().getId();

		for(CollectorItem collectorItem : collectorItems){
			if(collectorItem.getCollectorId().equals(collectorId) && collectorItem.getOptions().get("projectId").equals(request.getProjectId())){
				return collectorItem;
			}
		}
		
		return null;
	}

	@Override
	public RallyBurnDownResponse rallyBurnDownData(RallyFeature request) {

		RallyBurnDownResponse rallyBurnDownResponse = new RallyBurnDownResponse();
		List iterationDates = new ArrayList<>();
		List toDoHours = new ArrayList<>();
		List acceptedPoints = new ArrayList<>();
		List taskEstimateArray = new ArrayList<>();

		RallyBurnDownData burnDownData = rallyBurnDownRepository.findByIterationIdAndProjectId(request.getIterationId(),
				request.getProjectId());
		if(burnDownData!=null) {
		for (Map burnDownDetail : burnDownData.getBurnDownData()) {
			iterationDates.add(burnDownDetail.get(RallyBurnDownData.ITERATION_DATE).substring(5, 10));
			toDoHours.add(burnDownDetail.get(RallyBurnDownData.ITERATION_TO_DO_HOURS));
			acceptedPoints.add(Double.parseDouble(burnDownDetail.get(RallyBurnDownData.ACCEPTED_POINTS)));
		}

		double maximumTotalEstimate = burnDownData.getTotalEstimate();
		double estimateDiff = maximumTotalEstimate / (burnDownData.getBurnDownData().size() - 1);

		for (int j = 0; j < burnDownData.getBurnDownData().size(); j++) {
			if (burnDownData.getBurnDownData().size() - j == 1) {
				taskEstimateArray.add(0d);
			} else {
				taskEstimateArray
						.add(BigDecimal.valueOf(maximumTotalEstimate).setScale(2, RoundingMode.HALF_UP).doubleValue());
				maximumTotalEstimate = maximumTotalEstimate - estimateDiff;
			}
		}

		rallyBurnDownResponse.setAcceptedPoints(acceptedPoints);
		rallyBurnDownResponse.setToDoHours(toDoHours);
		rallyBurnDownResponse.setTotalTaskEstimate(taskEstimateArray);
		rallyBurnDownResponse.setIterationDates(iterationDates);
		}
		return rallyBurnDownResponse;

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy