TAK-71 TAK-73 history & post,get diagnosis

This commit is contained in:
Rafał Piskorski 2021-01-07 14:19:17 +01:00
parent 1651a41251
commit 6e79936b4c
24 changed files with 849 additions and 5 deletions

View File

@ -35,7 +35,8 @@ calculatorUI <- function(id){
htmlOutput("selected_var"), htmlOutput("selected_var"),
htmlOutput("var"), htmlOutput("var"),
br(), br(),
plotlyOutput("wykres") plotlyOutput("wykres"),
uiOutput("calculatorSave")
) )
)%>% tagAppendAttributes(id = 'column-content') )%>% tagAppendAttributes(id = 'column-content')
) %>% tagAppendAttributes(id = 'row-content'), ) %>% tagAppendAttributes(id = 'row-content'),
@ -51,7 +52,8 @@ calculatorUI <- function(id){
} }
calculatorServer <- function(input, output, session) { calculatorServer <- function(input, output, session) {
calculatorRV <-reactiveValues(value=NULL)
calculatorTV <-reactiveValues(value=NULL)
output$report <- downloadHandler( output$report <- downloadHandler(
# For PDF output, change this to "report.pdf" # For PDF output, change this to "report.pdf"
@ -90,9 +92,11 @@ calculatorServer <- function(input, output, session) {
} }
z=-5.3718+0.0354*as.numeric(isolate(input$slider1))+1.6159*as.numeric(isolate(input$select1))+1.1768*as.numeric(isolate(input$select2))+0.0697*p+0.9586*as.numeric(isolate(input$select3))-2.9486*as.numeric(isolate(input$select4)) z=-5.3718+0.0354*as.numeric(isolate(input$slider1))+1.6159*as.numeric(isolate(input$select1))+1.1768*as.numeric(isolate(input$select2))+0.0697*p+0.9586*as.numeric(isolate(input$select3))-2.9486*as.numeric(isolate(input$select4))
x=round(1/(1+exp(-z)),3) x=round(1/(1+exp(-z)),3)
calculatorRV$value<-x
if(as.numeric(input$update)>0){ if(as.numeric(input$update)>0){
paste("Surowa wartość predyktora (im niższa, tym lepiej): ", strong(x)) paste("Surowa wartość predyktora (im niższa, tym lepiej): ", strong(x))
} }
}) })
output$var <- renderText({ output$var <- renderText({
@ -106,8 +110,10 @@ calculatorServer <- function(input, output, session) {
if(as.numeric(input$update)>0){ if(as.numeric(input$update)>0){
if(x>0.1){ if(x>0.1){
paste("Klasa guza: ",strong("złośliwy")) paste("Klasa guza: ",strong("złośliwy"))
calculatorTV$value<-paste("Klasa guza: ",strong("złośliwy"))
} else { } else {
paste("Klasa guza: ",strong("łagodny")) paste("Klasa guza: ",strong("łagodny"))
calculatorTV$value <- paste("Klasa guza: ",strong("łagodny"))
} }
} }
}) })
@ -135,5 +141,62 @@ calculatorServer <- function(input, output, session) {
}) })
output$calculatorSave<-renderUI({
if(as.numeric(input$update)>0){
actionButton("calculatorSubmit","Zapisz")
}
})
observeEvent(input$calculatorSubmit, {
calculatorSave<-data.frame(slider1<-input$slider1,
select1<-input$select1,
select2<-input$select2,
slider2<-input$slider2,
select3<-input$select3,
select4<-input$select4)
calculatorParameterInts = list(list(name="parameter1",value = calculatorSave$slider1),
list(name="parameter2",value = calculatorSave$select1),
list(name="parameter3",value = calculatorSave$select2),
list(name="parameter4",value = calculatorSave$slider2),
list(name="parameter5",value = calculatorSave$select3),
list(name="parameter6",value = calculatorSave$select4))
prediction = list(
name = "IOTA",
parameterInts = calculatorParameterInts,
resultValue = calculatorRV$value,
resultText = calculatorTV$value
)
r<-httr::POST("http://localhost:8080/api/prediction/save/ind",add_headers(Authorization=paste("Bearer",input$token,sep=" ")),body=prediction,encode = 'json')
# SPRAWDZENIE POBIERANIA JEDNEGO I WIELU POMIAROW
# r<-httr::GET("http://localhost:8080/api/prediction/get/13",add_headers(Authorization=paste("Bearer",input$token,sep=" ")),encode = 'json')
# r<-httr::GET("http://localhost:8080/api/prediction/usersPredictions/ind",add_headers(Authorization=paste("Bearer",input$token,sep=" ")),encode = 'json')
if (r$status_code==200){
TRUE
}else{
FALSE
}
print(toJSON(content(r,as = "parsed")))
})
} }

View File

@ -286,7 +286,14 @@ text-align:center;
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
#calculatorSubmit{
align-self:center;
background-color:#028090;
color:white;
font-weight:bold;
border:none;
box-shadow: 0px 4px 4px rgb(255 255 255 / 25%);
}
#submit,#loginBtn,#editSubmit{ #submit,#loginBtn,#editSubmit{
margin-top:20px; margin-top:20px;
align-self:center; align-self:center;

View File

@ -0,0 +1,23 @@
package project.DTO;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
public class AlgorithmDTO implements Serializable {
@Getter
@Setter
private int id;
@Getter
@Setter
private String name;
public AlgorithmDTO(){}
}

View File

@ -0,0 +1,79 @@
package project.DTO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import project.model.ParameterDouble;
import project.model.ParameterInt;
import project.model.Prediction;
import project.model.User;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
public class PredictionDTO implements Serializable {
@Getter
@Setter
private int id;
@Getter
@Setter
private String name;
@Getter
@Setter
private int user;
@Getter
@Setter
private List<ParameterDouble> parameterDoubles;
@Getter
@Setter
private List<ParameterInt> parameterInts;
@Getter
@Setter
private double resultValue;
@Getter
@Setter
private String resultText;
@Getter
@Setter
private LocalDateTime localDateTime;
public PredictionDTO(){};
public PredictionDTO(PredictionDTO predictionDTO){
this.id = predictionDTO.getId();
this.name = predictionDTO.getName();
this.user = predictionDTO.getUser();
this.parameterDoubles = predictionDTO.getParameterDoubles();
this.parameterInts = predictionDTO.getParameterInts();
this.resultValue = predictionDTO.getResultValue();
this.resultText = predictionDTO.getResultText();
this.localDateTime = predictionDTO.getLocalDateTime();
}
public PredictionDTO(Prediction prediction){
this.id = prediction.getId();
this.name = prediction.getName();
this.user = prediction.getUser().getId();
this.parameterDoubles = prediction.getParameterDoubles();
this.parameterInts = prediction.getParameterInts();
this.resultValue = prediction.getResultValue();
this.resultText = prediction.getResultText();
this.localDateTime = prediction.getLocalDateTime();
}
}

View File

@ -1,8 +1,10 @@
package project.config; package project.config;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@ -23,6 +25,8 @@ import java.util.Arrays;
@EnableGlobalMethodSecurity(prePostEnabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity @EnableWebSecurity
@Configuration @Configuration
@EnableConfigurationProperties
@PropertySource("classpath:remote.properties")
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired @Autowired

View File

@ -0,0 +1,166 @@
package project.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
import project.DTO.PredictionDTO;
import project.DTO.UserDTO;
import project.config.TokenHelper;
import project.model.Prediction;
import project.model.User;
import project.services.GeneratorDTO;
import project.services.PredictionService;
import project.services.UserService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@RestController
@RequestMapping("/api/prediction")
public class PredictionController {
@Autowired
private PredictionService predictionService;
@Autowired
private UserService userService;
@Autowired
private GeneratorDTO generatorDTO;
@Autowired
private TokenHelper tokenHelper;
@PreAuthorize("hasAnyAuthority('IND')")
@RequestMapping(value = "/save/ind",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String,Object> addPrediction(@RequestBody @Valid @NotNull PredictionDTO predictionDTO,
HttpServletRequest request,
HttpServletResponse httpServletResponse){
Map<String,Object> map = new HashMap<>();
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Optional<User> user = userService.getUsersByLogin(userDetails.getUsername());
if (user.isPresent()) {
User currentUser = user.get();
Object token = request.getAttribute("token");
map.put("token", tokenHelper.refreshToken(token.toString()));
predictionDTO.setUser(currentUser.getId());
Prediction predictionSaved = this.predictionService.savePrediction(predictionDTO);
if (predictionSaved!=null){
map.put("prediction", new PredictionDTO(predictionSaved));
httpServletResponse.setStatus(200);
}else{
map.put("prediction", null);
httpServletResponse.setStatus(400);
}
}
else {
map.put("message", "Błąd autoryzacji");
httpServletResponse.setStatus(401);
}
return map;
}
@PreAuthorize("hasAnyAuthority('COMP','IND')")
@RequestMapping(value = "/get/{id}",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String,Object>> getPrediction(@PathVariable int id,
HttpServletRequest request,
HttpServletResponse httpServletResponse){
Map<String,Object> map = new HashMap<>();
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Optional<User> user = userService.getUsersByLogin(userDetails.getUsername());
if (user.isPresent()) {
User currentUser = user.get();
Object token = request.getAttribute("token");
map.put("token", tokenHelper.refreshToken(token.toString()));
Prediction prediction = this.predictionService.getPrediction(id);
if (prediction!=null){
map.put("prediction", new PredictionDTO(prediction));
return new ResponseEntity<Map<String,Object>>(map, HttpStatus.ACCEPTED);
}else{
map.put("prediction", null);
return new ResponseEntity<Map<String,Object>>(map, HttpStatus.BAD_REQUEST);
}
}
else {
map.put("message", "Błąd autoryzacji");
return new ResponseEntity<Map<String,Object>>(map, HttpStatus.UNAUTHORIZED);
}
}
@PreAuthorize("hasAnyAuthority('IND')")
@RequestMapping(value = "/usersPredictions/ind",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String,Object>> getUsersPredictions(HttpServletRequest request,
HttpServletResponse httpServletResponse){
Map<String,Object> map = new HashMap<>();
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Optional<User> user = userService.getUsersByLogin(userDetails.getUsername());
if (user.isPresent()) {
User currentUser = user.get();
Object token = request.getAttribute("token");
map.put("token", tokenHelper.refreshToken(token.toString()));
List<Prediction> predictions = this.predictionService.getAllPredictionsForUser(currentUser.getId());
if (predictions!=null){
map.put("predictions", this.generatorDTO.generatePredictionsDTO(predictions));
return new ResponseEntity<Map<String,Object>>(map, HttpStatus.ACCEPTED);
}else{
map.put("predictions", null);
return new ResponseEntity<Map<String,Object>>(map, HttpStatus.BAD_REQUEST);
}
}
else {
map.put("message", "Błąd autoryzacji");
return new ResponseEntity<Map<String,Object>>(map, HttpStatus.UNAUTHORIZED);
}
}
}

View File

@ -0,0 +1,26 @@
package project.model;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="Algorithm")
public class Algorithm implements Serializable {
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id",nullable=false)
private int id;
@Getter
@Setter
@Column(name="name")
private String name;
public Algorithm(){}
}

View File

@ -0,0 +1,44 @@
package project.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="ParameterDouble")
public class ParameterDouble implements Serializable {
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id",nullable=false)
private int id;
@Getter
@Setter
@Column(name="value",nullable=false)
private double value;
@Getter
@Setter
@ManyToOne
@JoinColumn(name = "prediction",referencedColumnName = "id")
// @JsonIgnoreProperties({"name", "user","parameterDoubles","parameterInts","resultValue","resultText"})
@JsonIgnore
private Prediction prediction;
public ParameterDouble(double value){
this.value=value;
}
public ParameterDouble(Prediction prediction,double value){
this.prediction=prediction;
this.value=value;
}
public ParameterDouble(){}
}

View File

@ -0,0 +1,41 @@
package project.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="ParameterInt")
public class ParameterInt implements Serializable {
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id",nullable=false)
private int id;
@Getter
@Setter
@Column(name="value",nullable=false)
private int value;
@Getter
@Setter
@ManyToOne
@JoinColumn(name="prediction",referencedColumnName = "id")
// @JsonIgnoreProperties({"name", "user","parameterDoubles","parameterInts","resultValue","resultText"})
@JsonIgnore
private Prediction prediction;
public ParameterInt(int value){
this.value=value;
}
public ParameterInt(){}
}

View File

@ -0,0 +1,77 @@
package project.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import project.DTO.PredictionDTO;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Entity
@Table(name="Prediction")
public class Prediction implements Serializable {
@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id",nullable = false)
private int id;
@Getter
@Setter
@Column(name="name",nullable=false)
private String name;
@Getter
@Setter
@ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user;
@Getter
@Setter
@OneToMany(mappedBy = "prediction",orphanRemoval = true, cascade = CascadeType.PERSIST)
@JsonIgnore
private List<ParameterDouble> parameterDoubles;
@Getter
@Setter
@OneToMany(mappedBy = "prediction",orphanRemoval = true, cascade = CascadeType.PERSIST)
@JsonIgnore
private List<ParameterInt> parameterInts;
@Getter
@Setter
@Column(name="resultValue",nullable = false)
private double resultValue;
@Getter
@Setter
@Column(name="date",nullable = false)
private LocalDateTime localDateTime;
@Getter
@Setter
@Column(name="resultText",nullable = false)
private String resultText;
public Prediction(){};
public Prediction(PredictionDTO predictionDTO){
this.name = predictionDTO.getName();
this.parameterDoubles = predictionDTO.getParameterDoubles();
this.parameterInts = predictionDTO.getParameterInts();
this.resultValue = predictionDTO.getResultValue();
this.resultText = predictionDTO.getResultText();
}
}

View File

@ -73,6 +73,12 @@ public class User implements Serializable {
@JoinColumn(name = "role",nullable=false) @JoinColumn(name = "role",nullable=false)
private Role role; private Role role;
@Getter
@Setter
@OneToMany(mappedBy = "user",orphanRemoval = true,cascade = CascadeType.PERSIST)
@JsonIgnore
private List<Prediction> predictions;
public User(){ public User(){
} }
@ -97,6 +103,7 @@ public class User implements Serializable {
this.login = user.getLogin(); this.login = user.getLogin();
this.password = user.getPassword(); this.password = user.getPassword();
this.role = user.getRole(); this.role = user.getRole();
this.predictions = user.getPredictions();
} }

View File

@ -0,0 +1,10 @@
package project.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import project.model.ParameterDouble;
import project.model.Role;
@Repository
public interface ParameterDoubleRepository extends JpaRepository<ParameterDouble,Integer> {
}

View File

@ -0,0 +1,10 @@
package project.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import project.model.ParameterInt;
import project.model.Role;
@Repository
public interface ParameterIntRepository extends JpaRepository<ParameterInt,Integer> {
}

View File

@ -0,0 +1,20 @@
package project.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import project.model.Prediction;
import project.model.Role;
import project.model.User;
import java.util.List;
import java.util.Optional;
@Repository
public interface PredictionRepository extends JpaRepository<Prediction,Integer> {
@Query(value="SELECT * FROM prediction p WHERE p.user_id=:userId", nativeQuery = true)
public Optional<List<Prediction>> findByUserId(@Param("userId") int userId);
}

View File

@ -2,11 +2,15 @@ package project.services;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import project.DTO.PredictionDTO;
import project.DTO.RoleDTO; import project.DTO.RoleDTO;
import project.DTO.UserDTO; import project.DTO.UserDTO;
import project.model.Prediction;
import project.model.User; import project.model.User;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Service @Service
public class GeneratorDTO implements Serializable { public class GeneratorDTO implements Serializable {
@ -19,4 +23,13 @@ public class GeneratorDTO implements Serializable {
return userDTO; return userDTO;
} }
public List<PredictionDTO> generatePredictionsDTO(
List<Prediction> predictionList){
List<PredictionDTO> predictionDTOS = new ArrayList<>();
for (Prediction prediction:predictionList) {
predictionDTOS.add(new PredictionDTO(prediction));
}
return predictionDTOS;
}
} }

View File

@ -0,0 +1,13 @@
package project.services;
import project.DTO.PredictionDTO;
import project.model.Prediction;
import java.util.List;
public interface PredictionService {
public Prediction savePrediction(PredictionDTO predictionDTO);
public Prediction getPrediction(int id);
public List<Prediction> getAllPredictionsForUser(int userId);
}

View File

@ -0,0 +1,87 @@
package project.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import project.DTO.PredictionDTO;
import project.model.ParameterDouble;
import project.model.ParameterInt;
import project.model.Prediction;
import project.repositories.ParameterDoubleRepository;
import project.repositories.ParameterIntRepository;
import project.repositories.PredictionRepository;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class PredictionServiceImpl implements PredictionService {
@Autowired
private PredictionRepository predictionRepository;
@Autowired
private ParameterIntRepository parameterIntRepository;
@Autowired
private ParameterDoubleRepository parameterDoubleRepository;
@Autowired
private UserServiceImpl userService;
public Prediction savePrediction(PredictionDTO predictionDTO){
Prediction prediction = new Prediction(predictionDTO);
prediction.setParameterDoubles(null);
prediction.setParameterInts(null);
prediction.setLocalDateTime(LocalDateTime.now());
prediction.setUser(userService.getUserById(predictionDTO.getUser()));
Prediction savedPrediction = this.predictionRepository.save(prediction);
List<ParameterInt> parameterInts = new ArrayList<>();
List<ParameterDouble> parameterDoubles = new ArrayList<>();
List<ParameterInt> parameterIntsDTO = predictionDTO.getParameterInts();
List<ParameterDouble> parameterDoublesDTO = predictionDTO.getParameterDoubles();
if(parameterIntsDTO !=null){
for (ParameterInt x:predictionDTO.getParameterInts()) {
x.setPrediction(savedPrediction);
parameterInts.add(parameterIntRepository.save(x));
}
}
savedPrediction.setParameterInts(parameterInts);
if(parameterDoublesDTO != null){
for (ParameterDouble x:predictionDTO.getParameterDoubles()) {
x.setPrediction(savedPrediction);
parameterDoubles.add(parameterDoubleRepository.save(x));
}
}
savedPrediction.setParameterDoubles(parameterDoubles);
// return prediction;
return this.predictionRepository.save(savedPrediction);
}
public Prediction getPrediction(int id){
Optional<Prediction> predictionOptional= this.predictionRepository.findById(id);
if(predictionOptional.isPresent()){
return predictionOptional.get();
}
return null;
}
public List<Prediction> getAllPredictionsForUser(int userId){
Optional<List<Prediction>> optionalPredictions = predictionRepository.findByUserId(userId);
if(optionalPredictions.isPresent()){
return optionalPredictions.get();
}
return null;
}
}

View File

@ -1,6 +1,7 @@
package project.services; package project.services;
import project.DTO.UserDTO; import project.DTO.UserDTO;
import project.model.Prediction;
import project.model.User; import project.model.User;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -19,4 +20,5 @@ public interface UserService {
public boolean checkIfCorrect(UserDTO userDTO,boolean edit); public boolean checkIfCorrect(UserDTO userDTO,boolean edit);
} }

View File

@ -13,6 +13,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import project.DTO.UserDTO; import project.DTO.UserDTO;
import project.model.CustomUserDetails; import project.model.CustomUserDetails;
import project.model.Prediction;
import project.model.User; import project.model.User;
import project.repositories.UserRepository; import project.repositories.UserRepository;
@ -104,4 +105,6 @@ public class UserServiceImpl implements UserService,UserDetailsService {
} }
} }

View File

@ -0,0 +1,26 @@
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:postgresql://localhost:5432/takecareapp?hibernate?useUnicode=yes&characterEncoding=UTF-8
#spring.jpa.generate-ddl=true
#hibernate?useUnicode=yes&characterEncoding=UTF-8
spring.datasource.username = postgres
spring.datasource.password = postgres
#useSSL=false
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
#Tomcat session timeout nir moze byc mniejszy niz 1 minuta
#server.servlet.session.timeout=60s
#spring.session.store-type=jdbc
#spring.session.jdbc.initialize-schema=always
#spring.session.timeout.seconds=10

View File

@ -6,8 +6,7 @@ spring.datasource.url = jdbc:postgresql://ec2-52-208-138-246.eu-west-1.compute.a
spring.datasource.username = nxpxoyywdkzdgy spring.datasource.username = nxpxoyywdkzdgy
spring.datasource.password = 4b0a06a3be25b34d0bf40a3be2049f779f5602e1793944643871a9a146557966 spring.datasource.password = 4b0a06a3be25b34d0bf40a3be2049f779f5602e1793944643871a9a146557966
#spring.datasource.username = postgres
#spring.datasource.password = postgres
#useSSL=false #useSSL=false

View File

@ -0,0 +1,4 @@
package project;
public class TakeCareAppTest {
}

View File

@ -0,0 +1,84 @@
package project.services;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import project.DTO.PredictionDTO;
import project.DTO.UserDTO;
import project.model.ParameterDouble;
import project.model.ParameterInt;
import project.model.Prediction;
import project.repositories.PredictionRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@RunWith(SpringRunner.class)
@SpringBootTest
public class PredictionServiceImplTest {
@Autowired
private PredictionServiceImpl predictionService;
public PredictionDTO generatePredictionDTO(){
PredictionDTO predictionDTO = new PredictionDTO();
predictionDTO.setName("Przykład");
predictionDTO.setUser(1);
List<ParameterDouble> parameterDoubles = new ArrayList<>();
List<ParameterInt> parameterInts = new ArrayList<>();
double[] tableDouble = {1.2,1.5,8.5,6.3,9.9,25.1};
int[] tableInt = {7,54,3,6,8,4,33,66,85,44,1001};
for (double x:tableDouble) {
parameterDoubles.add(new ParameterDouble(x));
}
for (int x:tableInt) {
parameterInts.add(new ParameterInt(x));
}
predictionDTO.setParameterInts(parameterInts);
predictionDTO.setParameterDoubles(parameterDoubles);
predictionDTO.setResultValue(0.98);
predictionDTO.setResultText("Otrzymany wynik świadczy o b. wysokim prawdopodobieństwie zachorowalności.");
return predictionDTO;
}
@Test
public void saveTest(){
PredictionDTO predictionDTO = generatePredictionDTO();
Prediction prediction = predictionService.savePrediction(predictionDTO);
System.out.println(prediction.getParameterInts());
Assert.assertTrue(prediction!=null);
}
@Test
public void getTest(){
Prediction prediction = predictionService.getPrediction(8);
Assert.assertTrue(prediction.getName()!=null);
Assert.assertTrue(prediction.getUser()!=null);
Assert.assertTrue(prediction.getParameterDoubles()!=null);
Assert.assertTrue(prediction.getParameterInts()!=null);
Object d = prediction.getResultValue();
Object t = prediction.getResultText();
Assert.assertTrue(d instanceof Double);
Assert.assertTrue(t instanceof String);
}
@Test
public void getAllTest(){
List<Prediction> predictions = predictionService.getAllPredictionsForUser(1);
Assert.assertTrue(predictions!=null);
Assert.assertTrue(predictions.size()!=0);
}
}

View File

@ -0,0 +1,36 @@
package project.services;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import project.DTO.UserDTO;
import project.repositories.UserRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceImplTest {
@Autowired
public UserServiceImpl userServiceImpl;
public UserDTO generateUserDTO(){
UserDTO userDTO = new UserDTO();
userDTO.setName(" ");
userDTO.setSurname(" ");
userDTO.setEmail(" ");
return userDTO;
}
@Test
public void checkIfCorrectTest(){
UserDTO userDTO = generateUserDTO();
UserServiceImpl userService = new UserServiceImpl();
boolean response = userService.checkIfCorrect(userDTO,false);
Assert.assertTrue(response==false);
}
}