Skip to content

Commit

Permalink
Issue 85: refactor Remote Product to Remote Project
Browse files Browse the repository at this point in the history
This includes fixing the URL.
Remote Projects should not be under the Product URL.

A new controller is brought in for providing `/projects/remote/by-product/{productId}`.

Fetching all remote projects was moved out of the `/products` URL and into the `/remote-project-manager` URL as follows:
- `/remote-project-manager/{remoteProjectManagerId}/remote-projects`
- `/remote-project-manager/{remoteProjectManagerId}/remote-projects/{scopeId}`
  • Loading branch information
kaladay committed May 19, 2020
1 parent e0fa3c6 commit cf6418d
Show file tree
Hide file tree
Showing 43 changed files with 954 additions and 758 deletions.
8 changes: 4 additions & 4 deletions src/main/java/edu/tamu/app/ProjectInitialization.java
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
8 changes: 4 additions & 4 deletions src/main/java/edu/tamu/app/cache/RemoteProjectsCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import java.util.List;
import java.util.Map;

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

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/products/remote")
public class RemoteProductsCacheController extends AbstractCacheController<RemoteProductsScheduledCacheService> {
@RequestMapping("/projects/remote")
public class RemoteProjectsCacheController extends AbstractCacheController<RemoteProjectsScheduledCacheService> {

}
6 changes: 3 additions & 3 deletions src/main/java/edu/tamu/app/cache/model/RemoteProject.java
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,74 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import edu.tamu.app.cache.RemoteProductsCache;
import edu.tamu.app.cache.model.RemoteProduct;
import edu.tamu.app.model.RemoteProductManager;
import edu.tamu.app.model.repo.RemoteProductManagerRepo;
import edu.tamu.app.service.manager.RemoteProductManagerBean;
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 RemoteProductsScheduledCacheService extends AbstractScheduledCacheService<Map<Long, List<RemoteProduct>>, RemoteProductsCache> {
public class RemoteProjectsScheduledCacheService extends AbstractScheduledCacheService<Map<Long, List<RemoteProject>>, RemoteProjectsCache> {

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

@Autowired
private RemoteProductManagerRepo remoteProductManagerRepo;
private RemoteProjectManagerRepo remoteProjectManagerRepo;

@Autowired
private ManagementBeanRegistry managementBeanRegistry;

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

@Override
@Scheduled(initialDelayString = "${app.cache.remote-products.delay}", fixedDelayString = "${app.cache.remote-products.interval}")
@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 products...");
logger.info("Caching remote projects...");

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

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

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

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

public Optional<RemoteProduct> getRemoteProduct(Long remoteProductManagerId, String scopeId) {
Optional<RemoteProduct> remoteProduct = Optional.empty();
Optional<List<RemoteProduct>> remoteProducts = Optional.ofNullable(get().get(remoteProductManagerId));
if (remoteProducts.isPresent()) {
for (RemoteProduct rp : remoteProducts.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)) {
remoteProduct = Optional.of(rp);
remoteProject = Optional.of(rp);
break;
}
}
}
return remoteProduct;
return remoteProject;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import edu.tamu.app.model.InternalRequest;
import edu.tamu.app.model.InternalStats;
import edu.tamu.app.model.Product;
import edu.tamu.app.model.RemoteProductManager;
import edu.tamu.app.model.RemoteProjectManager;
import edu.tamu.app.model.repo.InternalRequestRepo;
import edu.tamu.app.model.repo.ProductRepo;
import edu.tamu.app.model.repo.RemoteProductManagerRepo;
import edu.tamu.app.model.repo.RemoteProjectManagerRepo;
import edu.tamu.app.model.request.FeatureRequest;
import edu.tamu.app.service.manager.RemoteProductManagerBean;
import edu.tamu.app.service.manager.RemoteProjectManagerBean;
import edu.tamu.app.service.registry.ManagementBeanRegistry;
import edu.tamu.weaver.response.ApiResponse;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidatedModel;
Expand All @@ -47,7 +47,7 @@ public class InternalRequestController {
private ManagementBeanRegistry managementBeanRegistry;

@Autowired
private RemoteProductManagerRepo remoteProductManagerRepo;
private RemoteProjectManagerRepo remoteProjectManagerRepo;

@GetMapping
@PreAuthorize("hasRole('MANAGER')")
Expand Down Expand Up @@ -88,25 +88,25 @@ public ApiResponse delete(@WeaverValidatedModel InternalRequest internalRequest)
public ApiResponse push(@PathVariable Long requestId, @PathVariable Long productId, @PathVariable Long rpmId, @RequestBody String scopeId) {
Optional<InternalRequest> internalRequest = Optional.ofNullable(internalRequestRepo.findOne(requestId));
Optional<Product> product = Optional.ofNullable(productRepo.findOne(productId));
Optional<RemoteProductManager> remoteProductManager = Optional.ofNullable(remoteProductManagerRepo.findOne(rpmId));
Optional<RemoteProjectManager> remoteProjectManager = Optional.ofNullable(remoteProjectManagerRepo.findOne(rpmId));
ApiResponse response;

if (internalRequest.isPresent() && product.isPresent() && remoteProductManager.isPresent() && !scopeId.isEmpty()) {
if (internalRequest.isPresent() && product.isPresent() && remoteProjectManager.isPresent() && !scopeId.isEmpty()) {
FeatureRequest featureRequest = new FeatureRequest(
internalRequest.get().getTitle(), internalRequest.get().getDescription(), product.get().getId(), scopeId);

RemoteProductManagerBean remoteProductManagerBean =
(RemoteProductManagerBean) managementBeanRegistry.getService(remoteProductManager.get().getName());
RemoteProjectManagerBean remoteProjectManagerBean =
(RemoteProjectManagerBean) managementBeanRegistry.getService(remoteProjectManager.get().getName());

try {
response = new ApiResponse(SUCCESS, remoteProductManagerBean.push(featureRequest));
response = new ApiResponse(SUCCESS, remoteProjectManagerBean.push(featureRequest));
internalRequestRepo.delete(internalRequest.get());
} catch (Exception e) {
response = new ApiResponse(ERROR, "Error pushing Internal Request to " + remoteProductManager.get().getName()
response = new ApiResponse(ERROR, "Error pushing Internal Request to " + remoteProjectManager.get().getName()
+ " for Product " + product.get().getName() + "!");
}
} else if (!remoteProductManager.isPresent()) {
response = new ApiResponse(ERROR, "Remote Product Manager with id " + rpmId + " not found!");
} else if (!remoteProjectManager.isPresent()) {
response = new ApiResponse(ERROR, "Remote Project Manager with id " + rpmId + " not found!");
} else if (!internalRequest.isPresent()) {
response = new ApiResponse(ERROR, "Internal Request with id " + requestId + " not found!");
} else if (!product.isPresent()) {
Expand Down
Loading

0 comments on commit cf6418d

Please sign in to comment.