Skip to content

Commit

Permalink
Merge a554ea9 into e417a04
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed May 19, 2020
2 parents e417a04 + a554ea9 commit dd4d182
Show file tree
Hide file tree
Showing 56 changed files with 1,248 additions and 1,170 deletions.
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")
public class RemoteProjectsCacheController extends AbstractCacheController<RemoteProjectsScheduledCacheService> {

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package edu.tamu.app.cache.model;

public class RemoteProduct extends ProductStats {
public class RemoteProject extends ProductStats {

private static final long serialVersionUID = 8384046327331854613L;

public RemoteProduct() {
public RemoteProject() {
super();
}

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

Expand Down
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,10 @@

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 @@ -34,7 +34,7 @@ public class ProductsStatsScheduledCacheService extends AbstractProductScheduled
private InternalRequestRepo internalRequestRepo;

@Autowired
private RemoteProductsScheduledCacheService remoteProductsScheduledCacheService;
private RemoteProjectsScheduledCacheService remoteProjectsScheduledCacheService;

public ProductsStatsScheduledCacheService() {
super(new ProductsStatsCache());
Expand Down Expand Up @@ -97,17 +97,17 @@ private ProductStats getProductStats(Product product) {
internalCount = internalRequestRepo.countByProductId(productId.get());
}

List<RemoteProductInfo> remoteProductInfo = product.getRemoteProductInfo();
for (RemoteProductInfo rpi : remoteProductInfo) {
Optional<RemoteProductManager> remoteProductManager = Optional.ofNullable(rpi.getRemoteProductManager());
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();
}
}
}
Expand Down

This file was deleted.

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

import static edu.tamu.weaver.response.ApiStatus.SUCCESS;

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

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import edu.tamu.app.cache.RemoteProjectsCache;
import edu.tamu.app.cache.model.RemoteProject;
import edu.tamu.app.model.RemoteProjectManager;
import edu.tamu.app.model.repo.RemoteProjectManagerRepo;
import edu.tamu.app.service.manager.RemoteProjectManagerBean;
import edu.tamu.app.service.registry.ManagementBeanRegistry;
import edu.tamu.weaver.response.ApiResponse;

@Service
public class RemoteProjectsScheduledCacheService extends AbstractScheduledCacheService<Map<Long, List<RemoteProject>>, RemoteProjectsCache> {

private static final Logger logger = Logger.getLogger(RemoteProjectsScheduledCacheService.class);

@Autowired
private RemoteProjectManagerRepo remoteProjectManagerRepo;

@Autowired
private ManagementBeanRegistry managementBeanRegistry;

public RemoteProjectsScheduledCacheService() {
super(new RemoteProjectsCache());
}

@Override
@Scheduled(initialDelayString = "${app.cache.remote-projects.delay}", fixedDelayString = "${app.cache.remote-projects.interval}")
public void schedule() {
super.schedule();
}

public void update() {
logger.info("Caching remote projects...");

Map<Long, List<RemoteProject>> remoteProjects = new HashMap<Long, List<RemoteProject>>();
Optional<List<RemoteProjectManager>> remoteProjectManagers = Optional.ofNullable(remoteProjectManagerRepo.findAll());

if (remoteProjectManagers.isPresent()){
for (RemoteProjectManager remoteProjectManager : remoteProjectManagers.get()) {
RemoteProjectManagerBean remoteProjectManagerBean = (RemoteProjectManagerBean) managementBeanRegistry
.getService(remoteProjectManager.getName());
try {
remoteProjects.put(remoteProjectManager.getId(), remoteProjectManagerBean.getRemoteProject());
} catch (Exception e) {
e.printStackTrace();
}
}
}

set(remoteProjects);
logger.info("Finished caching remote projects");
}

public void broadcast() {
logger.info("Broadcasting cached remote projects");
simpMessagingTemplate.convertAndSend("/channel/projects/remote", new ApiResponse(SUCCESS, get()));
}

public Optional<RemoteProject> getRemoteProject(Long remoteProjectManagerId, String scopeId) {
Optional<RemoteProject> remoteProject = Optional.empty();
Optional<List<RemoteProject>> remoteProjects = Optional.ofNullable(get().get(remoteProjectManagerId));
if (remoteProjects.isPresent()) {
for (RemoteProject rp : remoteProjects.get()) {
if (rp.getId().equals(scopeId)) {
remoteProject = Optional.of(rp);
break;
}
}
}
return remoteProject;
}

@Override
public int getOrder() {
return 1;
}

}

0 comments on commit dd4d182

Please sign in to comment.