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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.tamu.app.controller;

import static edu.tamu.weaver.response.ApiStatus.INVALID;
import static edu.tamu.weaver.response.ApiStatus.SUCCESS;
import static edu.tamu.weaver.validation.model.BusinessValidationType.CREATE;

Expand All @@ -11,7 +12,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.app.enums.FeatureProposalState;
import edu.tamu.app.exception.UserNotFoundException;
import edu.tamu.app.model.FeatureProposal;
import edu.tamu.app.model.Idea;
Expand Down Expand Up @@ -63,6 +63,18 @@ public ApiResponse update(@WeaverValidatedModel FeatureProposal featureProposal)
return new ApiResponse(SUCCESS, featureProposalRepo.update(featureProposal));
}

@RequestMapping("/reject")
@PreAuthorize("hasRole('SERVICE_MANAGER')")
public ApiResponse reject(@WeaverValidatedModel FeatureProposal featureProposal) {
ApiResponse response;
if (featureProposal.getFeedback() == null || featureProposal.getFeedback().equals("")) {
response = new ApiResponse(INVALID, "You must provide feedback to reject a feature proposal.");
} else {
response = new ApiResponse(SUCCESS, featureProposalRepo.reject(featureProposal));
}
return response;
}

@Transactional
@RequestMapping("/remove")
@PreAuthorize("hasRole('SERVICE_MANAGER')")
Expand All @@ -79,12 +91,4 @@ public ApiResponse vote(@PathVariable Long id, @WeaverUser User voter) {
return new ApiResponse(SUCCESS, featureProposalRepo.update(featureProposal));
}

@RequestMapping("/{id}/reject")
@PreAuthorize("hasRole('SERVICE_MANAGER')")
public ApiResponse reject(@PathVariable Long id, @WeaverUser User voter) {
FeatureProposal featureProposal = featureProposalRepo.findOne(id);
featureProposal.setState(FeatureProposalState.REJECTED);
return new ApiResponse(SUCCESS, featureProposalRepo.update(featureProposal));
}

}
12 changes: 12 additions & 0 deletions src/main/java/edu/tamu/app/model/AbstractIdea.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public abstract class AbstractIdea extends ValidatingBaseEntity {
@Column(columnDefinition = "text", nullable = true)
private String description;

@Column(nullable = true)
private String feedback;

@Temporal(TemporalType.TIMESTAMP)
@UpdateTimestamp
private Calendar lastModified;
Expand All @@ -37,6 +40,7 @@ public abstract class AbstractIdea extends ValidatingBaseEntity {

public AbstractIdea() {
super();
this.feedback = "";
}

public AbstractIdea(String title, String description) {
Expand Down Expand Up @@ -75,6 +79,14 @@ public void setDescription(String description) {
this.description = description;
}

public String getFeedback() {
return feedback;
}

public void setFeedback(String feedback) {
this.feedback = feedback;
}

public Calendar getLastModified() {
return lastModified;
}
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/edu/tamu/app/model/Idea.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class Idea extends AbstractIdea {
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private IdeaState state;

@Column(nullable = true)
private String feedback;

@Column(nullable = true)
private String email;
Expand Down Expand Up @@ -67,7 +64,7 @@ public Idea(String title, String description, User author, Service service) {
super(title, description, author, service);
this.state = IdeaState.WAITING_ON_REVIEW;
}

public Idea(String title, String description, User author, Service service, String email) {
this(title, description, author, service);
this.email = email;
Expand All @@ -81,14 +78,6 @@ public void setState(IdeaState state) {
this.state = state;
}

public String getFeedback() {
return feedback;
}

public void setFeedback(String feedback) {
this.feedback = feedback;
}

public String getEmail() {
return email;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface FeatureProposalRepoCustom {

public void delete(FeatureProposal featureProposal);

public FeatureProposal reject(FeatureProposal featureProposal);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;

import edu.tamu.app.enums.FeatureProposalState;
import edu.tamu.app.enums.IdeaState;
import edu.tamu.app.exception.UserNotFoundException;
import edu.tamu.app.model.FeatureProposal;
Expand Down Expand Up @@ -89,4 +90,9 @@ public void delete(FeatureProposal featureProposal) {
simpMessagingTemplate.convertAndSend("/channel/feature-proposals/delete", new ApiResponse(SUCCESS, featureProposal.getId()));
}

public FeatureProposal reject(FeatureProposal featureProposal) {
featureProposal.setState(FeatureProposalState.REJECTED);
return featureProposalRepo.update(featureProposal);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import edu.tamu.app.enums.FeatureProposalState;
import edu.tamu.app.enums.Status;
import edu.tamu.app.exception.UserNotFoundException;
import edu.tamu.app.model.FeatureProposal;
Expand Down Expand Up @@ -52,15 +53,19 @@ public class FeatureProposalControllerTest {
private static final String TEST_MODIFIED_FEATURE_PROPOSAL_TITLE = "Modified Feature Proposal Title";
private static final String TEST_MODIFIED_FEATURE_PROPOSAL_DESCRIPTION = "Modified Feature Proposal Description";
private static final String TEST_SERVICE_NAME = "Test Service";
private static final String TEST_FEEDBACK = "Test Rejection Feedback";

private static Service TEST_SERVICE = new Service(TEST_SERVICE_NAME, Status.UP, false, true, true, "", "");
private static FeatureProposal TEST_FEATURE_PROPOSAL1 = new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE1, TEST_FEATURE_PROPOSAL_DESCRIPTION1, TEST_USER1);
private static FeatureProposal TEST_FEATURE_PROPOSAL2 = new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE2, TEST_FEATURE_PROPOSAL_DESCRIPTION2, TEST_USER1);
private static FeatureProposal TEST_FEATURE_PROPOSAL3 = new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE3, TEST_FEATURE_PROPOSAL_DESCRIPTION3, TEST_USER1);
private static FeatureProposal TEST_MODIFIED_FEATURE_PROPOSAL = new FeatureProposal(TEST_MODIFIED_FEATURE_PROPOSAL_TITLE, TEST_MODIFIED_FEATURE_PROPOSAL_DESCRIPTION, TEST_USER2, TEST_SERVICE);
private static FeatureProposal featureProposalWithFeedback = new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE1, TEST_FEATURE_PROPOSAL_DESCRIPTION1, TEST_USER1);
private static List<FeatureProposal> mockFeatureProposalList = new ArrayList<FeatureProposal>(Arrays.asList(new FeatureProposal[] { TEST_FEATURE_PROPOSAL1, TEST_FEATURE_PROPOSAL2, TEST_FEATURE_PROPOSAL3 }));
private static Page<FeatureProposal> mockPageableFeatureProposalList = new PageImpl<FeatureProposal>(Arrays.asList(new FeatureProposal[] { TEST_FEATURE_PROPOSAL1, TEST_FEATURE_PROPOSAL2, TEST_FEATURE_PROPOSAL3 }));

private FeatureProposal rejectedFeatureProposal = new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE1, TEST_FEATURE_PROPOSAL_DESCRIPTION1, TEST_USER1);

private static User user = new User("123456789");

private static ApiResponse response;
Expand All @@ -86,6 +91,8 @@ public class FeatureProposalControllerTest {
@Before
@SuppressWarnings("unchecked")
public void setup() throws UserNotFoundException {
rejectedFeatureProposal.setState(FeatureProposalState.REJECTED);
featureProposalWithFeedback.setFeedback(TEST_FEEDBACK);
MockitoAnnotations.initMocks(this);
when(credentials.getUin()).thenReturn("123456789");
when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(user));
Expand All @@ -95,6 +102,7 @@ public void setup() throws UserNotFoundException {
when(featureProposalRepo.create(any(FeatureProposal.class), any(Credentials.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
when(featureProposalRepo.create(any(Idea.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
when(featureProposalRepo.update(any(FeatureProposal.class))).thenReturn(TEST_MODIFIED_FEATURE_PROPOSAL);
when(featureProposalRepo.reject(TEST_FEATURE_PROPOSAL1)).thenReturn(rejectedFeatureProposal);
when(serviceRepo.findOne(any(Long.class))).thenReturn(TEST_SERVICE);
doNothing().when(featureProposalRepo).delete(any(FeatureProposal.class));
doNothing().when(featureProposalRepo).delete(any(FeatureProposal.class));
Expand Down Expand Up @@ -141,6 +149,14 @@ public void testUpdate() {
assertEquals("Notification Author was not properly updated", TEST_MODIFIED_FEATURE_PROPOSAL.getAuthor(), featureProposal.getAuthor());
}

@Test
public void testReject() {
response = featureProposalController.reject(featureProposalWithFeedback);
assertEquals("Not successful at rejecting feature proposal", SUCCESS, response.getMeta().getStatus());
FeatureProposal featureProposal = (FeatureProposal) response.getPayload().get("FeatureProposal");
assertEquals("State was not set to Rejected", rejectedFeatureProposal.getState(), featureProposal.getState());
}

@Test
public void testRemove() {
response = featureProposalController.remove(TEST_MODIFIED_FEATURE_PROPOSAL);
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 @@ -60,7 +60,7 @@ public class IdeaControllerTest {
private static Idea TEST_IDEA2 = new Idea(TEST_IDEA_TITLE2, TEST_IDEA_DESCRIPTION2, TEST_USER1);
private static Idea TEST_IDEA3 = new Idea(TEST_IDEA_TITLE3, TEST_IDEA_DESCRIPTION3, TEST_USER1);
private static Idea TEST_MODIFIED_IDEA = new Idea(TEST_MODIFIED_IDEA_TITLE, TEST_MODIFIED_IDEA_DESCRIPTION, TEST_USER2, TEST_SERVICE);
private static Idea ideaWtihFeedback = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1);
private static Idea ideaWithFeedback = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1);
private Idea rejectedIdea = new Idea(TEST_IDEA_TITLE1, TEST_IDEA_DESCRIPTION1, TEST_USER1);
private static List<Idea> mockIdeaList = new ArrayList<Idea>(Arrays.asList(new Idea[] { TEST_IDEA1, TEST_IDEA2, TEST_IDEA3 }));
private static Page<Idea> mockPageableIdeaList = new PageImpl<Idea>(Arrays.asList(new Idea[] { TEST_IDEA1, TEST_IDEA2, TEST_IDEA3 }));
Expand Down Expand Up @@ -91,7 +91,7 @@ public class IdeaControllerTest {
@SuppressWarnings("unchecked")
public void setup() throws UserNotFoundException {
rejectedIdea.setState(IdeaState.REJECTED);
ideaWtihFeedback.setFeedback(TEST_FEEDBACK);
ideaWithFeedback.setFeedback(TEST_FEEDBACK);
MockitoAnnotations.initMocks(this);
when(credentials.getUin()).thenReturn("123456789");
when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(user));
Expand Down Expand Up @@ -142,7 +142,7 @@ public void testUpdate() {

@Test
public void testReject() {
response = ideaController.reject(ideaWtihFeedback);
response = ideaController.reject(ideaWithFeedback);
assertEquals("Not successful at rejecting idea", SUCCESS, response.getMeta().getStatus());
Idea idea = (Idea) response.getPayload().get("Idea");
assertEquals("State was not set to Rejected", rejectedIdea.getState(), idea.getState());
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/edu/tamu/app/model/FeatureProposalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public class FeatureProposalTest {

private static final String TEST_FEATURE_PROPOSAL_TITLE = "Feature Proposal Title";
private static final String TEST_FEATURE_PROPOSAL_DESCRIPTION = "Test Feature Proposal Description";
private static final String TEST_FEATURE_PROPOSAL_FEEDBACK = "Feature Proposal Feedback";

private static final String TEST_SERVICE_NAME = "Test Service Name";
private static final String TEST_SERVICE_URL = "https://library.tamu.edu";
private static final String TEST_SERVICE_DESCRIPTION = "Test Service Description";

private static final String TEST_ALTERNATIVE_FEATURE_PROPOSAL_TITLE = "Alternative Feature Proposal Title";
private static final String TEST_ALTERNATIVE_FEATURE_PROPOSAL_DESCRIPTION = "Alternative Feature Proposal Description";
private static final String TEST_ALTERNATIVE_FEATURE_PROPOSAL_FEEDBACK = "Alternative Feature Proposal Feedback";

private static final String TEST_ALTERNATIVE_SERVICE_NAME = "Different Service Name";

Expand Down Expand Up @@ -197,6 +199,17 @@ public void testUpdateDescription() throws UserNotFoundException {
assertEquals("FeatureProposal body not updated", TEST_ALTERNATIVE_FEATURE_PROPOSAL_DESCRIPTION, featureProposal.getDescription());
}

@Test
public void testUpdateFeedback() throws UserNotFoundException {
FeatureProposal featureProposal = featureProposalRepo.create(testFeatureProposal, TEST_CREDENTIALS);
featureProposal.setFeedback(TEST_FEATURE_PROPOSAL_FEEDBACK);
featureProposal = featureProposalRepo.save(featureProposal);
assertEquals("FeatureProposal feedback not set", TEST_FEATURE_PROPOSAL_FEEDBACK, featureProposal.getFeedback());
featureProposal.setFeedback(TEST_ALTERNATIVE_FEATURE_PROPOSAL_FEEDBACK);
featureProposal = featureProposalRepo.save(featureProposal);
assertEquals("FeatureProposal feedback not updated", TEST_ALTERNATIVE_FEATURE_PROPOSAL_FEEDBACK, featureProposal.getFeedback());
}

@Test
public void testTimestampSetOnCreate() throws UserNotFoundException {
FeatureProposal FeatureProposal = featureProposalRepo.create(testFeatureProposal, TEST_CREDENTIALS);
Expand Down
31 changes: 24 additions & 7 deletions src/test/java/edu/tamu/app/model/IdeaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@
public class IdeaTest {

private static final String TEST_IDEA_TITLE = "Idea Title";
private static final String TEST_IDEA_DESCRIPTION = "Test Idea Description";
private static final String TEST_IDEA_FEEDBACK = "Idea Feedback";
private static final String TEST_IDEA_EMAIL = "aggiejack@mailinator.com";

private static final String TEST_SERVICE_NAME = "Test Service Name";
private static final String TEST_SERVICE_URL = "https://library.tamu.edu";
private static final String TEST_DESCRIPTION = "Test Service Description";
private static final String TEST_SERVICE_DESCRIPTION = "Test Service Description";

private static final String TEST_ALTERNATIVE_IDEA_TITLE = "Alternative Idea Title";
private static final String TEST_SERVICE_NAME = "Test Service Name";
private static final String TEST_ALTERNATIVE_SERVICE_NAME = "Different Service Name";
private static final String TEST_IDEA_DESCRIPTION = "Test Idea Description";
private static final String TEST_ALTERNATIVE_IDEA_FEEDBACK = "Alternative Idea Feedback";
private static final String TEST_ALTERNATIVE_IDEA_DESCRIPTION = "Alternative Idea Description";
private static final String TEST_IDEA_EMAIL = "aggiejack@mailinator.com";

private static final String TEST_ALTERNATIVE_SERVICE_NAME = "Different Service Name";

private static final Boolean TEST_IS_AUTO = false;
private static final Boolean TEST_IS_PUBLIC = true;
private static final Boolean TEST_ON_SHORT_LIST = true;
Expand Down Expand Up @@ -78,8 +84,8 @@ public class IdeaTest {
@Before
public void setUp() throws UserNotFoundException {
testUser = userRepo.create(TEST_CREDENTIALS.getUin(), TEST_CREDENTIALS.getEmail(), TEST_CREDENTIALS.getFirstName(), TEST_CREDENTIALS.getLastName(), Role.valueOf(TEST_CREDENTIALS.getRole()));
service1 = serviceRepo.create(new Service(TEST_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, TEST_SERVICE_URL, TEST_DESCRIPTION));
service2 = serviceRepo.create(new Service(TEST_ALTERNATIVE_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, TEST_SERVICE_URL, TEST_DESCRIPTION));
service1 = serviceRepo.create(new Service(TEST_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, TEST_SERVICE_URL, TEST_SERVICE_DESCRIPTION));
service2 = serviceRepo.create(new Service(TEST_ALTERNATIVE_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, TEST_SERVICE_URL, TEST_SERVICE_DESCRIPTION));
testIdea = ideaRepo.create(new Idea(TEST_IDEA_TITLE, TEST_IDEA_DESCRIPTION, testUser, service1, TEST_IDEA_EMAIL), TEST_CREDENTIALS);
testFeatureProposal = featureProposalRepo.create(new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE, TEST_FEATURE_PROPOSAL_DESCRIPTION, testUser, service1), TEST_CREDENTIALS);
}
Expand Down Expand Up @@ -133,6 +139,17 @@ public void testUpdateDescription() throws UserNotFoundException {
assertEquals("Idea body not updated", TEST_ALTERNATIVE_IDEA_DESCRIPTION, idea.getDescription());
}

@Test
public void testUpdateFeedback() throws UserNotFoundException {
Idea idea = ideaRepo.create(testIdea, TEST_CREDENTIALS);
idea.setFeedback(TEST_IDEA_FEEDBACK);
idea = ideaRepo.save(idea);
assertEquals("Idea feedback not set", TEST_IDEA_FEEDBACK, idea.getFeedback());
idea.setFeedback(TEST_ALTERNATIVE_IDEA_FEEDBACK);
idea = ideaRepo.save(idea);
assertEquals("Idea feedback not updated", TEST_ALTERNATIVE_IDEA_FEEDBACK, idea.getFeedback());
}

@Test
public void testUpdateFeatureProposal() throws UserNotFoundException {
Idea idea = ideaRepo.create(testIdea, TEST_CREDENTIALS);
Expand Down