Compare commits
No commits in common. "0f5c8389d8efe77ef325247c9b1e1733c7bd5ea8" and "71a7adc5fd4be9f12abe0efaf0a90507479ecc16" have entirely different histories.
0f5c8389d8
...
71a7adc5fd
@ -28,7 +28,7 @@ public class ProjectService {
|
||||
Project project = projectRepository
|
||||
.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Project not found by id"));
|
||||
checkIsCurrentUserProjectWithThrow(project);
|
||||
checkUserProjectWithThrow(project, userService.getCurrentUser());
|
||||
return project;
|
||||
}
|
||||
|
||||
@ -52,8 +52,8 @@ public class ProjectService {
|
||||
projectRepository.deleteById(projectForm.getId());
|
||||
}
|
||||
|
||||
public void checkIsCurrentUserProjectWithThrow(Project project) {
|
||||
if (!isUserProject(project, userService.getCurrentUser())) {
|
||||
private void checkUserProjectWithThrow(Project project, User currentUser) {
|
||||
if (!isUserProject(project, currentUser)) {
|
||||
throw new RuntimeException("User can not get access to project");
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,16 @@ public class FuzzyTermRestController {
|
||||
this.fuzzyTermService = fuzzyTermService;
|
||||
}
|
||||
|
||||
@GetMapping("/list/{variableId}")
|
||||
public List<FuzzyTerm> getList(@PathVariable(value = "variableId") Integer variableId) {
|
||||
return fuzzyTermService.getAll(variableId);
|
||||
@GetMapping("/list/{projectId}/{variableId}")
|
||||
public List<FuzzyTerm> getList(@PathVariable(value = "projectId") Integer projectId,
|
||||
@PathVariable(value = "variableId") Integer variableId) {
|
||||
return fuzzyTermService.getAll(projectId, variableId);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{fuzzyTermId}")
|
||||
public FuzzyTerm getById(@PathVariable(value = "fuzzyTermId") Integer fuzzyTermId) {
|
||||
@GetMapping("/get/{projectId}/{variableId}/{fuzzyTermId}")
|
||||
public FuzzyTerm getById(@PathVariable(value = "projectId") Integer projectId,
|
||||
@PathVariable(value = "variableId") Integer variableId,
|
||||
@PathVariable(value = "fuzzyTermId") Integer fuzzyTermId) {
|
||||
return fuzzyTermService.getById(fuzzyTermId);
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
package ru.ulstu.fc.rule.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
||||
import ru.ulstu.fc.rule.model.Variable;
|
||||
|
||||
public interface FuzzyTermRepository extends JpaRepository<FuzzyTerm, Integer> {
|
||||
|
||||
@Query("SELECT v FROM Variable v LEFT JOIN v.fuzzyTerms ft WHERE ft = :fuzzyTerm")
|
||||
Variable findByFuzzyTerm(@Param("fuzzyTerm") FuzzyTerm fuzzyTerm);
|
||||
}
|
||||
|
@ -11,18 +11,15 @@ public class FuzzyRuleService {
|
||||
private final FuzzyRuleRepository ruleRepository;
|
||||
private final ProjectService projectService;
|
||||
|
||||
public FuzzyRuleService(FuzzyRuleRepository ruleRepository,
|
||||
ProjectService projectService) {
|
||||
public FuzzyRuleService(FuzzyRuleRepository ruleRepository, ProjectService projectService) {
|
||||
this.ruleRepository = ruleRepository;
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
public FuzzyRule getById(Integer id) {
|
||||
FuzzyRule fuzzyRule = ruleRepository
|
||||
return ruleRepository
|
||||
.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Rule not found by id"));
|
||||
checkIsCurrentUserFuzzyRuleWithThrow(fuzzyRule);
|
||||
return fuzzyRule;
|
||||
}
|
||||
|
||||
public FuzzyRule save(FuzzyRuleForm ruleForm) {
|
||||
@ -38,10 +35,7 @@ public class FuzzyRuleService {
|
||||
}
|
||||
|
||||
public void delete(FuzzyRuleForm ruleForm) {
|
||||
ruleRepository.delete(getById(ruleForm.getId()));
|
||||
}
|
||||
|
||||
public void checkIsCurrentUserFuzzyRuleWithThrow(FuzzyRule fuzzyRule) {
|
||||
projectService.checkIsCurrentUserProjectWithThrow(fuzzyRule.getProject());
|
||||
getById(ruleForm.getId());
|
||||
ruleRepository.deleteById(ruleForm.getId());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ru.ulstu.fc.rule.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.fc.project.service.ProjectService;
|
||||
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
||||
import ru.ulstu.fc.rule.model.FuzzyTermForm;
|
||||
import ru.ulstu.fc.rule.repository.FuzzyTermRepository;
|
||||
@ -13,26 +12,20 @@ import java.util.List;
|
||||
public class FuzzyTermService {
|
||||
private final FuzzyTermRepository fuzzyTermRepository;
|
||||
private final VariableService variableService;
|
||||
private final ProjectService projectService;
|
||||
|
||||
public FuzzyTermService(FuzzyTermRepository fuzzyTermRepository,
|
||||
VariableService variableService,
|
||||
ProjectService projectService) {
|
||||
VariableService variableService) {
|
||||
this.fuzzyTermRepository = fuzzyTermRepository;
|
||||
this.variableService = variableService;
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
public FuzzyTerm getById(Integer id) {
|
||||
FuzzyTerm fuzzyTerm = fuzzyTermRepository
|
||||
return fuzzyTermRepository
|
||||
.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Term not found by id"));
|
||||
checkIsCurrentUserFuzzyTermWithThrow(fuzzyTerm);
|
||||
return fuzzyTerm;
|
||||
}
|
||||
|
||||
public FuzzyTerm save(FuzzyTermForm fuzzyTermForm) {
|
||||
variableService.getById(fuzzyTermForm.getVariableId());
|
||||
FuzzyTerm term;
|
||||
if (fuzzyTermForm.getId() == null || fuzzyTermForm.getId() == 0) {
|
||||
term = new FuzzyTerm();
|
||||
@ -46,10 +39,12 @@ public class FuzzyTermService {
|
||||
variableService.addFuzzyTerm(fuzzyTermForm.getVariableId(), ft);
|
||||
}
|
||||
return ft;
|
||||
|
||||
}
|
||||
|
||||
public void delete(FuzzyTermForm fuzzyTermForm) {
|
||||
fuzzyTermRepository.delete(getById(fuzzyTermForm.getId()));
|
||||
getById(fuzzyTermForm.getId());
|
||||
fuzzyTermRepository.deleteById(fuzzyTermForm.getId());
|
||||
}
|
||||
|
||||
public List<FuzzyTerm> getByVariableId(Integer variableId) {
|
||||
@ -59,12 +54,7 @@ public class FuzzyTermService {
|
||||
return variableService.getById(variableId).getFuzzyTerms();
|
||||
}
|
||||
|
||||
public List<FuzzyTerm> getAll(Integer variableId) {
|
||||
variableService.getById(variableId);
|
||||
public List<FuzzyTerm> getAll(Integer projectId, Integer variableId) {
|
||||
return getByVariableId(variableId);
|
||||
}
|
||||
|
||||
public void checkIsCurrentUserFuzzyTermWithThrow(FuzzyTerm fuzzyTerm) {
|
||||
projectService.checkIsCurrentUserProjectWithThrow(fuzzyTermRepository.findByFuzzyTerm(fuzzyTerm).getProject());
|
||||
}
|
||||
}
|
||||
|
@ -14,18 +14,15 @@ public class VariableService {
|
||||
private final VariableRepository variableRepository;
|
||||
private final ProjectService projectService;
|
||||
|
||||
public VariableService(VariableRepository variableRepository,
|
||||
ProjectService projectService) {
|
||||
public VariableService(VariableRepository variableRepository, ProjectService projectService) {
|
||||
this.variableRepository = variableRepository;
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
public Variable getById(Integer id) {
|
||||
Variable variable = variableRepository
|
||||
return variableRepository
|
||||
.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Variable not found by id"));
|
||||
checkIsCurrentUserVariableWithThrow(variable);
|
||||
return variable;
|
||||
}
|
||||
|
||||
public Variable save(VariableForm variableForm) {
|
||||
@ -68,8 +65,4 @@ public class VariableService {
|
||||
public List<Variable> getAllByProject(Integer projectId) {
|
||||
return variableRepository.getByProject(projectService.getById(projectId));
|
||||
}
|
||||
|
||||
public void checkIsCurrentUserVariableWithThrow(Variable variable) {
|
||||
projectService.checkIsCurrentUserProjectWithThrow(variable.getProject());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user