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
|
Project project = projectRepository
|
||||||
.findById(id)
|
.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Project not found by id"));
|
.orElseThrow(() -> new RuntimeException("Project not found by id"));
|
||||||
checkIsCurrentUserProjectWithThrow(project);
|
checkUserProjectWithThrow(project, userService.getCurrentUser());
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ public class ProjectService {
|
|||||||
projectRepository.deleteById(projectForm.getId());
|
projectRepository.deleteById(projectForm.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIsCurrentUserProjectWithThrow(Project project) {
|
private void checkUserProjectWithThrow(Project project, User currentUser) {
|
||||||
if (!isUserProject(project, userService.getCurrentUser())) {
|
if (!isUserProject(project, currentUser)) {
|
||||||
throw new RuntimeException("User can not get access to project");
|
throw new RuntimeException("User can not get access to project");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,16 @@ public class FuzzyTermRestController {
|
|||||||
this.fuzzyTermService = fuzzyTermService;
|
this.fuzzyTermService = fuzzyTermService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list/{variableId}")
|
@GetMapping("/list/{projectId}/{variableId}")
|
||||||
public List<FuzzyTerm> getList(@PathVariable(value = "variableId") Integer variableId) {
|
public List<FuzzyTerm> getList(@PathVariable(value = "projectId") Integer projectId,
|
||||||
return fuzzyTermService.getAll(variableId);
|
@PathVariable(value = "variableId") Integer variableId) {
|
||||||
|
return fuzzyTermService.getAll(projectId, variableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get/{fuzzyTermId}")
|
@GetMapping("/get/{projectId}/{variableId}/{fuzzyTermId}")
|
||||||
public FuzzyTerm getById(@PathVariable(value = "fuzzyTermId") Integer fuzzyTermId) {
|
public FuzzyTerm getById(@PathVariable(value = "projectId") Integer projectId,
|
||||||
|
@PathVariable(value = "variableId") Integer variableId,
|
||||||
|
@PathVariable(value = "fuzzyTermId") Integer fuzzyTermId) {
|
||||||
return fuzzyTermService.getById(fuzzyTermId);
|
return fuzzyTermService.getById(fuzzyTermId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package ru.ulstu.fc.rule.repository;
|
package ru.ulstu.fc.rule.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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.FuzzyTerm;
|
||||||
import ru.ulstu.fc.rule.model.Variable;
|
|
||||||
|
|
||||||
public interface FuzzyTermRepository extends JpaRepository<FuzzyTerm, Integer> {
|
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 FuzzyRuleRepository ruleRepository;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
|
|
||||||
public FuzzyRuleService(FuzzyRuleRepository ruleRepository,
|
public FuzzyRuleService(FuzzyRuleRepository ruleRepository, ProjectService projectService) {
|
||||||
ProjectService projectService) {
|
|
||||||
this.ruleRepository = ruleRepository;
|
this.ruleRepository = ruleRepository;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuzzyRule getById(Integer id) {
|
public FuzzyRule getById(Integer id) {
|
||||||
FuzzyRule fuzzyRule = ruleRepository
|
return ruleRepository
|
||||||
.findById(id)
|
.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Rule not found by id"));
|
.orElseThrow(() -> new RuntimeException("Rule not found by id"));
|
||||||
checkIsCurrentUserFuzzyRuleWithThrow(fuzzyRule);
|
|
||||||
return fuzzyRule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuzzyRule save(FuzzyRuleForm ruleForm) {
|
public FuzzyRule save(FuzzyRuleForm ruleForm) {
|
||||||
@ -38,10 +35,7 @@ public class FuzzyRuleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(FuzzyRuleForm ruleForm) {
|
public void delete(FuzzyRuleForm ruleForm) {
|
||||||
ruleRepository.delete(getById(ruleForm.getId()));
|
getById(ruleForm.getId());
|
||||||
}
|
ruleRepository.deleteById(ruleForm.getId());
|
||||||
|
|
||||||
public void checkIsCurrentUserFuzzyRuleWithThrow(FuzzyRule fuzzyRule) {
|
|
||||||
projectService.checkIsCurrentUserProjectWithThrow(fuzzyRule.getProject());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ru.ulstu.fc.rule.service;
|
package ru.ulstu.fc.rule.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.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.FuzzyTerm;
|
||||||
import ru.ulstu.fc.rule.model.FuzzyTermForm;
|
import ru.ulstu.fc.rule.model.FuzzyTermForm;
|
||||||
import ru.ulstu.fc.rule.repository.FuzzyTermRepository;
|
import ru.ulstu.fc.rule.repository.FuzzyTermRepository;
|
||||||
@ -13,26 +12,20 @@ import java.util.List;
|
|||||||
public class FuzzyTermService {
|
public class FuzzyTermService {
|
||||||
private final FuzzyTermRepository fuzzyTermRepository;
|
private final FuzzyTermRepository fuzzyTermRepository;
|
||||||
private final VariableService variableService;
|
private final VariableService variableService;
|
||||||
private final ProjectService projectService;
|
|
||||||
|
|
||||||
public FuzzyTermService(FuzzyTermRepository fuzzyTermRepository,
|
public FuzzyTermService(FuzzyTermRepository fuzzyTermRepository,
|
||||||
VariableService variableService,
|
VariableService variableService) {
|
||||||
ProjectService projectService) {
|
|
||||||
this.fuzzyTermRepository = fuzzyTermRepository;
|
this.fuzzyTermRepository = fuzzyTermRepository;
|
||||||
this.variableService = variableService;
|
this.variableService = variableService;
|
||||||
this.projectService = projectService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuzzyTerm getById(Integer id) {
|
public FuzzyTerm getById(Integer id) {
|
||||||
FuzzyTerm fuzzyTerm = fuzzyTermRepository
|
return fuzzyTermRepository
|
||||||
.findById(id)
|
.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Term not found by id"));
|
.orElseThrow(() -> new RuntimeException("Term not found by id"));
|
||||||
checkIsCurrentUserFuzzyTermWithThrow(fuzzyTerm);
|
|
||||||
return fuzzyTerm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuzzyTerm save(FuzzyTermForm fuzzyTermForm) {
|
public FuzzyTerm save(FuzzyTermForm fuzzyTermForm) {
|
||||||
variableService.getById(fuzzyTermForm.getVariableId());
|
|
||||||
FuzzyTerm term;
|
FuzzyTerm term;
|
||||||
if (fuzzyTermForm.getId() == null || fuzzyTermForm.getId() == 0) {
|
if (fuzzyTermForm.getId() == null || fuzzyTermForm.getId() == 0) {
|
||||||
term = new FuzzyTerm();
|
term = new FuzzyTerm();
|
||||||
@ -46,10 +39,12 @@ public class FuzzyTermService {
|
|||||||
variableService.addFuzzyTerm(fuzzyTermForm.getVariableId(), ft);
|
variableService.addFuzzyTerm(fuzzyTermForm.getVariableId(), ft);
|
||||||
}
|
}
|
||||||
return ft;
|
return ft;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(FuzzyTermForm fuzzyTermForm) {
|
public void delete(FuzzyTermForm fuzzyTermForm) {
|
||||||
fuzzyTermRepository.delete(getById(fuzzyTermForm.getId()));
|
getById(fuzzyTermForm.getId());
|
||||||
|
fuzzyTermRepository.deleteById(fuzzyTermForm.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FuzzyTerm> getByVariableId(Integer variableId) {
|
public List<FuzzyTerm> getByVariableId(Integer variableId) {
|
||||||
@ -59,12 +54,7 @@ public class FuzzyTermService {
|
|||||||
return variableService.getById(variableId).getFuzzyTerms();
|
return variableService.getById(variableId).getFuzzyTerms();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FuzzyTerm> getAll(Integer variableId) {
|
public List<FuzzyTerm> getAll(Integer projectId, Integer variableId) {
|
||||||
variableService.getById(variableId);
|
|
||||||
return getByVariableId(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 VariableRepository variableRepository;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
|
|
||||||
public VariableService(VariableRepository variableRepository,
|
public VariableService(VariableRepository variableRepository, ProjectService projectService) {
|
||||||
ProjectService projectService) {
|
|
||||||
this.variableRepository = variableRepository;
|
this.variableRepository = variableRepository;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable getById(Integer id) {
|
public Variable getById(Integer id) {
|
||||||
Variable variable = variableRepository
|
return variableRepository
|
||||||
.findById(id)
|
.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Variable not found by id"));
|
.orElseThrow(() -> new RuntimeException("Variable not found by id"));
|
||||||
checkIsCurrentUserVariableWithThrow(variable);
|
|
||||||
return variable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable save(VariableForm variableForm) {
|
public Variable save(VariableForm variableForm) {
|
||||||
@ -68,8 +65,4 @@ public class VariableService {
|
|||||||
public List<Variable> getAllByProject(Integer projectId) {
|
public List<Variable> getAllByProject(Integer projectId) {
|
||||||
return variableRepository.getByProject(projectService.getById(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