Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Remote Products to Remote Projects #90

Merged
merged 8 commits into from
May 21, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

import edu.tamu.app.model.CardType;
import edu.tamu.app.model.repo.CardTypeRepo;
import edu.tamu.app.model.repo.RemoteProductManagerRepo;
import edu.tamu.app.model.repo.RemoteProjectManagerRepo;
import edu.tamu.app.service.registry.ManagementBeanRegistry;

@Component
@Profile("!test")
public class ProductInitialization implements CommandLineRunner {
public class ProjectInitialization implements CommandLineRunner {

@Autowired
private ManagementBeanRegistry managementBeanRegistry;

@Autowired
private RemoteProductManagerRepo remoteProductManagerRepo;
private RemoteProjectManagerRepo remoteProjectManagerRepo;

@Autowired
private CardTypeRepo cardTypeRepo;

@Override
public void run(String... args) throws Exception {
remoteProductManagerRepo.findAll().forEach(versionManagementSoftware -> {
remoteProjectManagerRepo.findAll().forEach(versionManagementSoftware -> {
managementBeanRegistry.register(versionManagementSoftware);
});
CardType type = cardTypeRepo.findByIdentifier("Feature");
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/edu/tamu/app/cache/RemoteProductsCache.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/edu/tamu/app/cache/RemoteProjectsCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.tamu.app.cache;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.tamu.app.cache.model.RemoteProject;

public class RemoteProjectsCache extends AbstractCache<Map<Long, List<RemoteProject>>> {

public RemoteProjectsCache() {
set(new HashMap<Long, List<RemoteProject>>());
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package edu.tamu.app.cache.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.app.cache.service.RemoteProjectsScheduledCacheService;

@RestController
@RequestMapping("/projects/remote")
rladdusaw marked this conversation as resolved.
Show resolved Hide resolved
public class RemoteProjectsCacheController extends AbstractCacheController<RemoteProjectsScheduledCacheService> {

}
10 changes: 9 additions & 1 deletion src/main/java/edu/tamu/app/cache/model/ProductStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ProductStats implements Serializable {

private final long defectCount;

private final long internalCount;

public ProductStats() {
super();
id = "";
Expand All @@ -26,16 +28,18 @@ public ProductStats() {
issueCount = 0;
featureCount = 0;
defectCount = 0;
internalCount = 0;
}

public ProductStats(String id, String name, long requestCount, long issueCount, long featureCount, long defectCount) {
public ProductStats(String id, String name, long requestCount, long issueCount, long featureCount, long defectCount, long internalCount) {
super();
this.id = id;
this.name = name;
this.requestCount = requestCount;
this.issueCount = issueCount;
this.featureCount = featureCount;
this.defectCount = defectCount;
this.internalCount = internalCount;
}

public String getId() {
Expand All @@ -62,6 +66,10 @@ public long getDefectCount() {
return defectCount;
}

public long getInternalCount() {
return internalCount;
}

public long getBacklogItemCount() {
return featureCount + defectCount;
}
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/edu/tamu/app/cache/model/RemoteProduct.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/edu/tamu/app/cache/model/RemoteProject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.tamu.app.cache.model;

public class RemoteProject extends ProductStats {

private static final long serialVersionUID = 8384046327331854613L;

public RemoteProject() {
super();
}

public RemoteProject(String id, String name, long requestCount, long issueCount, long featureCount, long defectCount, long internalCount) {
super(id, name, requestCount, issueCount, featureCount, defectCount, internalCount);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import edu.tamu.app.cache.ActiveSprintsCache;
import edu.tamu.app.cache.model.Sprint;
import edu.tamu.app.model.Product;
import edu.tamu.app.model.RemoteProductInfo;
import edu.tamu.app.model.RemoteProjectInfo;
import edu.tamu.app.model.repo.ProductRepo;
import edu.tamu.app.service.manager.RemoteProductManagerBean;
import edu.tamu.app.service.manager.RemoteProjectManagerBean;
import edu.tamu.app.service.registry.ManagementBean;
import edu.tamu.weaver.response.ApiResponse;

Expand Down Expand Up @@ -46,7 +46,7 @@ public void update() {
activeSprints.addAll(fetchActiveSprints(product));
});
for (ManagementBean managementBean : managementBeanRegistry.getServices().values()) {
RemoteProductManagerBean rpm = (RemoteProductManagerBean) managementBean;
RemoteProjectManagerBean rpm = (RemoteProjectManagerBean) managementBean;
try {
activeSprints.addAll(rpm.getAdditionalActiveSprints());
} catch (Exception e) {
Expand Down Expand Up @@ -86,12 +86,12 @@ public void removeProduct(Product product) {

private List<Sprint> fetchActiveSprints(Product product) {
List<Sprint> activeSprints = new ArrayList<Sprint>();
Optional<List<RemoteProductInfo>> remoteProductInfo = Optional.ofNullable(product.getRemoteProductInfo());
if (remoteProductInfo.isPresent()) {
remoteProductInfo.get().forEach(rp -> {
RemoteProductManagerBean remoteProductManagerBean = (RemoteProductManagerBean) managementBeanRegistry.getService(rp.getRemoteProductManager().getName());
Optional<List<RemoteProjectInfo>> remoteProjectInfo = Optional.ofNullable(product.getRemoteProjectInfo());
if (remoteProjectInfo.isPresent()) {
remoteProjectInfo.get().forEach(rp -> {
RemoteProjectManagerBean remoteProjectManagerBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(rp.getRemoteProjectManager().getName());
try {
activeSprints.addAll(remoteProductManagerBean.getActiveSprintsByProductId(rp.getScopeId()));
activeSprints.addAll(remoteProjectManagerBean.getActiveSprintsByScopeId(rp.getScopeId()));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

import edu.tamu.app.cache.ProductsStatsCache;
import edu.tamu.app.cache.model.ProductStats;
import edu.tamu.app.cache.model.RemoteProduct;
import edu.tamu.app.cache.model.RemoteProject;
import edu.tamu.app.model.Product;
import edu.tamu.app.model.RemoteProductInfo;
import edu.tamu.app.model.RemoteProductManager;
import edu.tamu.app.model.RemoteProjectInfo;
import edu.tamu.app.model.RemoteProjectManager;
import edu.tamu.app.model.repo.InternalRequestRepo;
import edu.tamu.app.model.repo.ProductRepo;
import edu.tamu.weaver.response.ApiResponse;

Expand All @@ -30,7 +31,10 @@ public class ProductsStatsScheduledCacheService extends AbstractProductScheduled
private ProductRepo productRepo;

@Autowired
private RemoteProductsScheduledCacheService remoteProductsScheduledCacheService;
private InternalRequestRepo internalRequestRepo;

@Autowired
private RemoteProjectsScheduledCacheService remoteProjectsScheduledCacheService;

public ProductsStatsScheduledCacheService() {
super(new ProductsStatsCache());
Expand Down Expand Up @@ -82,27 +86,33 @@ public void removeProduct(Product product) {
private ProductStats getProductStats(Product product) {
String id = product.getId().toString();
String name = product.getName();
int requestCount = 0;
int issueCount = 0;
int featureCount = 0;
int defectCount = 0;

List<RemoteProductInfo> remoteProductInfo = product.getRemoteProductInfo();
for (RemoteProductInfo rpi : remoteProductInfo) {
Optional<RemoteProductManager> remoteProductManager = Optional.ofNullable(rpi.getRemoteProductManager());
long requestCount = 0;
long issueCount = 0;
long featureCount = 0;
long defectCount = 0;
long internalCount = 0;

Optional<Long> productId = Optional.ofNullable(product.getId());
if (productId.isPresent()) {
internalCount = internalRequestRepo.countByProductId(productId.get());
}

List<RemoteProjectInfo> remoteProjectInfo = product.getRemoteProjectInfo();
for (RemoteProjectInfo rpi : remoteProjectInfo) {
Optional<RemoteProjectManager> remoteProjectManager = Optional.ofNullable(rpi.getRemoteProjectManager());
Optional<String> scopeId = Optional.ofNullable(rpi.getScopeId());
if (remoteProductManager.isPresent() && scopeId.isPresent()) {
Optional<RemoteProduct> remoteProduct = remoteProductsScheduledCacheService.getRemoteProduct(remoteProductManager.get().getId(), scopeId.get());
if (remoteProduct.isPresent()) {
requestCount += remoteProduct.get().getRequestCount();
issueCount += remoteProduct.get().getIssueCount();
featureCount += remoteProduct.get().getFeatureCount();
defectCount += remoteProduct.get().getDefectCount();
if (remoteProjectManager.isPresent() && scopeId.isPresent()) {
Optional<RemoteProject> remoteProject = remoteProjectsScheduledCacheService.getRemoteProject(remoteProjectManager.get().getId(), scopeId.get());
if (remoteProject.isPresent()) {
requestCount += remoteProject.get().getRequestCount();
issueCount += remoteProject.get().getIssueCount();
featureCount += remoteProject.get().getFeatureCount();
defectCount += remoteProject.get().getDefectCount();
}
}
}

return new ProductStats(id, name, requestCount, issueCount, featureCount, defectCount);
return new ProductStats(id, name, requestCount, issueCount, featureCount, defectCount, internalCount);
}

@Override
Expand Down

This file was deleted.