UPDATE:: achievement things, tests/checkstyle and it actually works now

This commit is contained in:
mlwauben
2019-04-03 20:34:04 +02:00
parent 973e8aba69
commit 28f9f72f07
11 changed files with 108 additions and 56 deletions

View File

@@ -1,20 +0,0 @@
package greenify.client.controller;
import greenify.client.rest.UserService;
import javafx.fxml.FXML;
import javafx.scene.image.ImageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
* Class that controls the achievements fxml file (the GUI Screen).
*/
@Controller
public class AchievementsTestController {
@Autowired
UserService userService;
@FXML
private ImageView achievpic1;
}

View File

@@ -13,6 +13,7 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.util.Map;
/**
* Class that controls the dashboard fxml file (the GUI Screen).
@@ -60,6 +62,8 @@ public class DashBoardController {
private Button calculateFootPrintButton;
@FXML
private Label footprintLabel;
@FXML
private ImageView achiev1image;
/**
* Loads the the necessary things before anything else.
@@ -74,8 +78,7 @@ public class DashBoardController {
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
userButton.setSkin(new MyButtonSkin(userButton));
friendsButton.setSkin(new MyButtonSkin(friendsButton));
updateAchievements();
}
/**
@@ -102,7 +105,7 @@ public class DashBoardController {
userPane.setVisible(false);
activitiesPane.setVisible(false);
friendsPane.setVisible(false);
updateAchievements();
}
/**
@@ -172,6 +175,16 @@ public class DashBoardController {
calcStage.show();
}
/**
* Updates the achievements.
*/
public void updateAchievements() {
Map achievements = userService.getAchievements(userService.currentUser.getName());
achiev1image.setVisible((Boolean)achievements.get("Starting off"));
//achiev2image.setVisible(achievements.get("name second achievement"));
//Add all achievements here, add updateAchievements to the achievements pane
}
//class for the animations on the navigation buttons
public class MyButtonSkin extends ButtonSkin {
/**

View File

@@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
@Service
public class UserService {
public UserDto currentUser;
@@ -134,4 +136,22 @@ public class UserService {
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
}
/**
* Gets the achievements of a user.
* @param name name of the user
* @return Map with all achievements
*/
@SuppressWarnings("Duplicates")
public Map getAchievements(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getAchievements")
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
return this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class);
}
}

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.AchievementsTestController">
<children>
<ImageView fx:id="achievpic1" fitHeight="98.0" fitWidth="75.0" layoutX="179.0" layoutY="153.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../achiev1pic.jpg" />
</image>
</ImageView>
<Text layoutX="177.0" layoutY="149.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Tom Dumoulin" />
</children>
</AnchorPane>

View File

@@ -1,14 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
<children>
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
<children>
@@ -41,7 +47,8 @@
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
</children></AnchorPane>
</children>
</AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
@@ -239,6 +246,12 @@
</ImageView>
</graphic>
</Button>
<ImageView fx:id="achiev1image" fitHeight="150.0" fitWidth="200.0" layoutX="126.0" layoutY="431.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../achiev1pic.jpg" />
</image>
</ImageView>
<Label fx:id="achiev1text" layoutX="126.0" layoutY="414.0" prefHeight="18.0" prefWidth="181.0" text="Achievement 1 " />
</children>
</AnchorPane>
<AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

View File

@@ -62,6 +62,12 @@ public class UserServiceTest {
userService.addFriend("Eric", "Ceren");
Mockito.verify(userService).addFriend("Eric", "Ceren");
}
@Test
public void getAchievementsTest() throws Exception {
userService.getAchievements("mika");
Mockito.verify(userService).getAchievements("mika");
}
}

View File

@@ -7,6 +7,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
public class UserController {
@Autowired
@@ -47,7 +49,6 @@ public class UserController {
public void setInput(@RequestParam(value = "name") String name,
@RequestParam(value = "inputName") String inputName,
@RequestParam(value = "value") String value) {
System.out.println("Here is server controller");
userService.setInput(name, inputName, value);
}
@@ -83,9 +84,13 @@ public class UserController {
userService.addFriend(name, friend);
}
/* @RequestMapping("/addAchievement")
public void addAchievement(@RequestParam(value = "name") String name,
@RequestParam(value = "achievement") String achievement) {
userService.achievementAchieved(name, achievement);
}*/
/**
* This method gets all achievements of a user.
* @param name name of the user
* @return map of all achievements of the user
*/
@RequestMapping("/getAchievements")
public Map<String, Boolean> getAchievements(@RequestParam(value = "name") String name) {
return userService.getAchievements(name);
}
}

View File

@@ -6,7 +6,9 @@ import greenify.server.data.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AchievementService {
@Autowired
UserService userService;

View File

@@ -13,6 +13,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
@Service
public class UserService {
@Autowired
@@ -177,6 +179,17 @@ public class UserService {
}
}
/**
* This method gets all achievements of a user.
* @param name name of the user
* @return map with all achievements of a user
*/
public Map<String, Boolean> getAchievements(String name) {
User user = userRepository.findByName(name);
return user.getAchievements();
}
/**
* This method gets a JSON of XML with all users.
* @return JSON/XML of all users

View File

@@ -120,4 +120,16 @@ public class UserControllerTest {
verify(userService, times(1)).getFootprint(arg1Captor.capture());
assertEquals("ceren", arg1Captor.getValue());
}
@Test
public void getAchievementsTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/getAchievements")
.param("name", "mika")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
verify(userService, times(1)).getAchievements(arg1Captor.capture());
assertEquals("mika", arg1Captor.getValue());
}
}

View File

@@ -6,6 +6,7 @@ import static org.mockito.Mockito.when;
import greenify.common.ApplicationException;
import greenify.common.UserDto;
import greenify.server.AllAchievements;
import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository;
import org.junit.Before;
@@ -201,4 +202,9 @@ public class UserServiceTest {
assertThrows(ApplicationException.class, () -> userService.getAchievement("alex", "hello"));
assertEquals(false, userService.getAchievement("alex", "Starting off"));
}
@Test
public void getAchievementsTest() {
assertEquals(AllAchievements.getDefaults(), userService.getAchievements("alex"));
}
}