Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/edu/tamu/app/controller/IdeaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import edu.tamu.app.model.repo.IdeaRepo;
import edu.tamu.app.model.request.FilteredPageRequest;
import edu.tamu.app.model.request.IssueRequest;
import edu.tamu.app.service.ProjectService;
import edu.tamu.app.service.ProductService;
import edu.tamu.weaver.auth.annotation.WeaverCredentials;
import edu.tamu.weaver.auth.model.Credentials;
import edu.tamu.weaver.response.ApiResponse;
Expand All @@ -33,7 +33,7 @@ public class IdeaController {
private IdeaRepo ideaRepo;

@Autowired
private ProjectService projectService;
private ProductService productService;

@RequestMapping("/page")
@PreAuthorize("hasRole('SERVICE_MANAGER')")
Expand Down Expand Up @@ -78,7 +78,7 @@ public ApiResponse helpdesk(@WeaverValidatedModel Idea idea, @WeaverCredentials
idea.setState(IdeaState.SENT_TO_HELPDESK);
idea = ideaRepo.update(idea);
IssueRequest request = new IssueRequest(idea, credentials);
return projectService.submitIssueRequest(request);
return productService.submitIssueRequest(request);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@

import edu.tamu.app.exception.UserNotFoundException;
import edu.tamu.app.model.FeatureProposal;
import edu.tamu.app.service.ProjectService;
import edu.tamu.app.service.ProductService;
import edu.tamu.weaver.response.ApiResponse;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidatedModel;

@RestController
@RequestMapping("/projects")
public class ProjectController {
@RequestMapping("/products")
public class ProductController {

@Autowired
private ProjectService projectService;
private ProductService productService;

@RequestMapping
@PreAuthorize("hasRole('USER')")
public ApiResponse getAll() throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
return projectService.getAll();
return productService.getAll();
}

@RequestMapping("/{id}")
@PreAuthorize("hasRole('ANONYMOUS')")
public ApiResponse getById(@PathVariable Long id) throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
return projectService.getById(id);
return productService.getById(id);
}

@RequestMapping("/feature")
@PreAuthorize("hasRole('SERVICE_MANAGER')")
public ApiResponse submitFeatureRequest(@WeaverValidatedModel FeatureProposal proposal) throws UserNotFoundException {
return projectService.submitFeatureRequest(proposal);
return productService.submitFeatureRequest(proposal);
}

}
6 changes: 3 additions & 3 deletions src/main/java/edu/tamu/app/controller/ServiceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import edu.tamu.app.model.request.FilteredPageRequest;
import edu.tamu.app.model.request.IssueRequest;
import edu.tamu.app.model.request.ServiceRequest;
import edu.tamu.app.service.ProjectService;
import edu.tamu.app.service.ProductService;
import edu.tamu.weaver.auth.annotation.WeaverCredentials;
import edu.tamu.weaver.auth.model.Credentials;
import edu.tamu.weaver.response.ApiResponse;
Expand All @@ -39,7 +39,7 @@ public class ServiceController {
private IdeaRepo ideaRepo;

@Autowired
private ProjectService projectService;
private ProductService productService;

@RequestMapping
@PreAuthorize("hasRole('ANONYMOUS')")
Expand Down Expand Up @@ -94,7 +94,7 @@ public ApiResponse submitIssueRequest(@RequestBody ServiceRequest request, @Weav
Service service = serviceRepo.findOne(request.getService());
issueRequest.setService(service.getName());
issueRequest.setCredentials(credentials);
return projectService.submitIssueRequest(issueRequest);
return productService.submitIssueRequest(issueRequest);
}

@RequestMapping("/feature")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.app.mock.projects.MockProjects;
import edu.tamu.app.mock.products.MockProducts;
import edu.tamu.app.model.request.FeatureRequest;
import edu.tamu.weaver.response.ApiResponse;

@RestController
@Profile("test")
@RequestMapping("/mock/projects")
public class MockProjectManagementController {
@RequestMapping("/mock/products")
public class MockProductManagementController {

@Autowired
private MockProjects mockProjects;
private MockProducts mockProducts;

@RequestMapping
public ApiResponse getAll() {
return new ApiResponse(SUCCESS, mockProjects.getAllProjects());
return new ApiResponse(SUCCESS, mockProducts.getAllProducts());
}

@RequestMapping("/{id}")
public ApiResponse getById(@PathVariable Long id) {
return new ApiResponse(SUCCESS, mockProjects.getProjectById(id));
return new ApiResponse(SUCCESS, mockProducts.getProductById(id));
}

@RequestMapping("/issue")
public ApiResponse submitIssue(@RequestBody FeatureRequest request) {
return new ApiResponse(SUCCESS, mockProjects.submitRequest(request));
return new ApiResponse(SUCCESS, mockProducts.submitRequest(request));
}

@RequestMapping("/feature")
public ApiResponse submitFeature(@RequestBody FeatureRequest request) {
return new ApiResponse(SUCCESS, mockProjects.submitRequest(request));
return new ApiResponse(SUCCESS, mockProducts.submitRequest(request));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.tamu.app.mock.projects;
package edu.tamu.app.mock.products;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -19,41 +19,41 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.tamu.app.model.request.FeatureRequest;
import edu.tamu.app.model.response.Project;
import edu.tamu.app.model.response.Product;

@Service
@Profile("test")
public class MockProjects {
public class MockProducts {

private static List<Project> projects = new ArrayList<Project>();
private static List<Product> products = new ArrayList<Product>();

@Value("classpath:mock/projects.json")
@Value("classpath:mock/products.json")
private Resource resource;

@Autowired
private ObjectMapper objectMapper;

@PostConstruct
private void loadProjects() throws JsonParseException, JsonMappingException, IOException {
projects = objectMapper.readValue(resource.getFile(), new TypeReference<List<Project>>() {});
private void loadProducts() throws JsonParseException, JsonMappingException, IOException {
products = objectMapper.readValue(resource.getFile(), new TypeReference<List<Product>>() {});
}

public List<Project> getAllProjects() {
return projects;
public List<Product> getAllProducts() {
return products;
}

public Project getProjectById(Long id) {
Project project = null;
for (Project currentProject : projects) {
Optional<Long> currentId = Optional.ofNullable(Long.valueOf(currentProject.getId()));
public Product getProductById(Long id) {
Product product = null;
for (Product currentProduct : products) {
Optional<Long> currentId = Optional.ofNullable(Long.valueOf(currentProduct.getId()));
if (currentId.isPresent()) {
if (currentId.get().equals(id)) {
project = currentProject;
product = currentProduct;
break;
}
}
}
return project;
return product;
}

public String submitRequest(FeatureRequest request) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/edu/tamu/app/model/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Service extends AbstractScheduler {
private String software;

@Column(nullable = true)
private Long projectId;
private Long productId;

public Service() {
super();
Expand Down Expand Up @@ -150,12 +150,12 @@ public void setSoftware(String software) {
this.software = software;
}

public Long getProjectId() {
return projectId;
public Long getProductId() {
return productId;
}

public void setProjectId(Long projectId) {
this.projectId = projectId;
public void setProductId(Long productId) {
this.productId = productId;
}

@Override
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/edu/tamu/app/model/request/FeatureRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class FeatureRequest extends AbstractRequest {

private static final long serialVersionUID = -6953745180846929244L;

private Long projectId;
private Long productId;

public FeatureRequest() {
super();
Expand All @@ -20,21 +20,21 @@ public FeatureRequest(RequestType type, String title, String description) {
super(type, title, description);
}

public FeatureRequest(RequestType type, String title, String description, Long projectId) {
public FeatureRequest(RequestType type, String title, String description, Long productId) {
this(type, title, description);
this.projectId = projectId;
this.productId = productId;
}

public FeatureRequest(FeatureProposal proposal) {
this(RequestType.FEATURE, proposal.getTitle(), proposal.getDescription(), proposal.getService().getProjectId());
this(RequestType.FEATURE, proposal.getTitle(), proposal.getDescription(), proposal.getService().getProductId());
}

public Long getProjectId() {
return projectId;
public Long getProductId() {
return productId;
}

public void setProjectId(Long projectId) {
this.projectId = projectId;
public void setProductId(Long productId) {
this.productId = productId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import java.io.Serializable;

public class Project implements Serializable {
public class Product implements Serializable {

private static final long serialVersionUID = -6339048161691523620L;

private Long id;

private String name;

public Project() {
public Product() {
super();
}

public Project(Long id, String name) {
public Product(Long id, String name) {
this();
this.id = id;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import edu.tamu.weaver.response.ApiStatus;;

@Service
public class ProjectService {
public class ProductService {

@Value("${app.projects.url}")
private String projectsUrl;
@Value("${app.products.url}")
private String productsUrl;

@Autowired
private ObjectMapper objectMapper;
Expand All @@ -43,15 +43,15 @@ public class ProjectService {
private SimpMessagingTemplate simpMessagingTemplate;

public ApiResponse getAll() throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
return objectMapper.readValue(new URL(projectsUrl), ApiResponse.class);
return objectMapper.readValue(new URL(productsUrl), ApiResponse.class);
}

public ApiResponse getById(Long id) throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
return objectMapper.readValue(new URL(projectsUrl + "/" + id), ApiResponse.class);
return objectMapper.readValue(new URL(productsUrl + "/" + id), ApiResponse.class);
}

public ApiResponse submitFeatureRequest(FeatureProposal proposal) {
ApiResponse response = restTemplate.postForObject(projectsUrl + "/feature", new FeatureRequest(proposal), ApiResponse.class);
ApiResponse response = restTemplate.postForObject(productsUrl + "/feature", new FeatureRequest(proposal), ApiResponse.class);
if (response.getMeta().getStatus().equals(ApiStatus.SUCCESS)) {
proposal.setState(FeatureProposalState.SUBMITTED);
proposal = featureProposalRepo.save(proposal);
Expand All @@ -61,7 +61,7 @@ public ApiResponse submitFeatureRequest(FeatureProposal proposal) {
}

public ApiResponse submitIssueRequest(IssueRequest request) {
return restTemplate.postForObject(projectsUrl + "/issue", request, ApiResponse.class);
return restTemplate.postForObject(productsUrl + "/issue", request, ApiResponse.class);

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spring:

---
app:
projects.url: http://localhost:9001/projects
products.url: http://localhost:9001/products

whitelist: 127.0.0.1

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/edu/tamu/app/controller/IdeaControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import edu.tamu.app.model.repo.specification.IdeaSpecification;
import edu.tamu.app.model.request.FilteredPageRequest;
import edu.tamu.app.model.request.IssueRequest;
import edu.tamu.app.service.ProjectService;
import edu.tamu.app.service.ProductService;
import edu.tamu.weaver.auth.model.Credentials;
import edu.tamu.weaver.response.ApiResponse;

Expand Down Expand Up @@ -91,7 +91,7 @@ public class IdeaControllerTest {
private ServiceRepo serviceRepo;

@Mock
private ProjectService projectService;
private ProductService productService;

@Mock
private SimpMessagingTemplate simpMessagingTemplate;
Expand All @@ -117,7 +117,7 @@ public void setup() throws UserNotFoundException {
when(ideaRepo.update(any(Idea.class))).thenReturn(TEST_MODIFIED_IDEA);
when(ideaRepo.reject(TEST_IDEA1)).thenReturn(rejectedIdea);
when(serviceRepo.findOne(any(Long.class))).thenReturn(TEST_SERVICE);
when(projectService.submitIssueRequest(any(IssueRequest.class))).thenReturn(new ApiResponse(SUCCESS, TEST_ISSUE_REQUEST));
when(productService.submitIssueRequest(any(IssueRequest.class))).thenReturn(new ApiResponse(SUCCESS, TEST_ISSUE_REQUEST));
doNothing().when(ideaRepo).delete(any(Idea.class));
doNothing().when(ideaRepo).delete(any(Idea.class));
}
Expand Down
Loading