#6 -- Check permissions to the terms
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m38s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m38s
This commit is contained in:
parent
0093416e6c
commit
4bec9ee870
@ -22,16 +22,13 @@ public class FuzzyTermRestController {
|
|||||||
this.fuzzyTermService = fuzzyTermService;
|
this.fuzzyTermService = fuzzyTermService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list/{projectId}/{variableId}")
|
@GetMapping("/list/{variableId}")
|
||||||
public List<FuzzyTerm> getList(@PathVariable(value = "projectId") Integer projectId,
|
public List<FuzzyTerm> getList(@PathVariable(value = "variableId") Integer variableId) {
|
||||||
@PathVariable(value = "variableId") Integer variableId) {
|
return fuzzyTermService.getAll(variableId);
|
||||||
return fuzzyTermService.getAll(projectId, variableId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get/{projectId}/{variableId}/{fuzzyTermId}")
|
@GetMapping("/get/{fuzzyTermId}")
|
||||||
public FuzzyTerm getById(@PathVariable(value = "projectId") Integer projectId,
|
public FuzzyTerm getById(@PathVariable(value = "fuzzyTermId") Integer fuzzyTermId) {
|
||||||
@PathVariable(value = "variableId") Integer variableId,
|
|
||||||
@PathVariable(value = "fuzzyTermId") Integer fuzzyTermId) {
|
|
||||||
return fuzzyTermService.getById(fuzzyTermId);
|
return fuzzyTermService.getById(fuzzyTermId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
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;
|
||||||
@ -12,20 +13,26 @@ 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) {
|
||||||
return fuzzyTermRepository
|
FuzzyTerm fuzzyTerm = 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();
|
||||||
@ -39,12 +46,10 @@ 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) {
|
||||||
getById(fuzzyTermForm.getId());
|
fuzzyTermRepository.delete(getById(fuzzyTermForm.getId()));
|
||||||
fuzzyTermRepository.deleteById(fuzzyTermForm.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FuzzyTerm> getByVariableId(Integer variableId) {
|
public List<FuzzyTerm> getByVariableId(Integer variableId) {
|
||||||
@ -54,7 +59,12 @@ public class FuzzyTermService {
|
|||||||
return variableService.getById(variableId).getFuzzyTerms();
|
return variableService.getById(variableId).getFuzzyTerms();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FuzzyTerm> getAll(Integer projectId, Integer variableId) {
|
public List<FuzzyTerm> getAll(Integer variableId) {
|
||||||
|
variableService.getById(variableId);
|
||||||
return getByVariableId(variableId);
|
return getByVariableId(variableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkIsCurrentUserFuzzyTermWithThrow(FuzzyTerm fuzzyTerm) {
|
||||||
|
projectService.checkIsCurrentUserProjectWithThrow(fuzzyTermRepository.findByFuzzyTerm(fuzzyTerm).getProject());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user