From ab709164f60d2954b47c83142f5036422bd22135 Mon Sep 17 00:00:00 2001 From: nt Date: Mon, 13 Nov 2023 18:52:19 +0100 Subject: [PATCH] Removed lots of unused code (especially unused API endpoints) --- .../power/controller/CategoryController.java | 50 +-------------- .../hbt/power/controller/SkillController.java | 62 +++---------------- .../power/repo/SkillCategoryRepository.java | 7 --- .../de/hbt/power/repo/SkillRepository.java | 11 ---- .../de/hbt/power/service/CategoryService.java | 8 +-- .../de/hbt/power/service/SkillService.java | 7 --- .../service/SkillTreeMappingService.java | 4 -- .../CategoryServiceIntegrationTest.java | 8 --- ...llSearcherService_ExpectedResultITest.java | 7 +-- .../hbt/power/service/SkillServiceTest.java | 17 +---- 10 files changed, 19 insertions(+), 162 deletions(-) diff --git a/src/main/java/de/hbt/power/controller/CategoryController.java b/src/main/java/de/hbt/power/controller/CategoryController.java index b74805d..5265c8b 100644 --- a/src/main/java/de/hbt/power/controller/CategoryController.java +++ b/src/main/java/de/hbt/power/controller/CategoryController.java @@ -1,10 +1,8 @@ package de.hbt.power.controller; import de.hbt.power.exception.SkillServiceException; -import de.hbt.power.model.Skill; import de.hbt.power.model.SkillCategory; import de.hbt.power.repo.SkillCategoryRepository; -import de.hbt.power.repo.SkillRepository; import de.hbt.power.service.CategoryService; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -29,15 +27,13 @@ allowCredentials = "true") public class CategoryController { private final SkillCategoryRepository skillCategoryRepository; - private final SkillRepository skillRepository; private final CategoryService categoryService; @Autowired - CategoryController(SkillCategoryRepository skillCategoryRepository, SkillRepository skillRepository, CategoryService categoryService, SkillRepository skillRepository1, CategoryService categoryService1) { + CategoryController(SkillCategoryRepository skillCategoryRepository, CategoryService categoryService1) { this.skillCategoryRepository = skillCategoryRepository; - this.skillRepository = skillRepository1; this.categoryService = categoryService1; } @@ -48,25 +44,6 @@ public ResponseEntity> getAllCategoryIds() { return ResponseEntity.ok(categories); } - /** - * Returns all root categories -> categories without a parent - */ - @ApiOperation(value = "Returns all root IDs", - notes = "Returns all available root categories ids. A root category has no direct parent. It might happen that the" + - "returned list is empty, indicating a server or database problem. (The list should not be empty, there are always root categories.)", - response = Integer.class, - responseContainer = "List", - httpMethod = "GET", - produces = "application/json") - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Returns the root category ids in response. May be empty.", response = List.class), - }) - @GetMapping(value = "/root") - public ResponseEntity> getRootCategoryIds() { - final List ids = skillCategoryRepository.findAllByCategoryIsNull().stream().map(SkillCategory::getId).collect(Collectors.toList()); - return ResponseEntity.ok(ids); - } - @ApiOperation(value = "Returns all child IDs", notes = "For a given category ID, returns the IDs of all categories that are direct children to this category.", response = Integer.class, @@ -86,21 +63,6 @@ public ResponseEntity> getChildrenIds(@PathVariable("id") Integer return ResponseEntity.ok(childIds); } - @ApiOperation(value = "Returns all child Skills", - notes = "For a given category ID, returns all skills that are direct children to that category.", - response = Skill.class, - responseContainer = "List", - httpMethod = "GET", - produces = "application/json") - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Child Skills returned in response. May be empty.") - }) - @GetMapping(value = "/{id}/skills") - public ResponseEntity> getChildSkills(@PathVariable("id") Integer id) { - return ResponseEntity.ok(skillRepository.findAllByCategory_Id(id)); - } - - @ApiOperation(value = "Returns a category", notes = "Returns the category identified by the given ID.", response = SkillCategory.class, @@ -167,7 +129,7 @@ public ResponseEntity createCategory(@RequestBody() SkillCategory }) @DeleteMapping(value = "/{id}") @Transactional - public ResponseEntity deleteCategory(@PathVariable("id") Integer categoryId) { + public ResponseEntity deleteCategory(@PathVariable("id") Integer categoryId) { SkillCategory skillCategory = getCategory(categoryId); log.info("Deleting the " + skillCategory.toString()); @@ -312,14 +274,6 @@ public ResponseEntity deleteFromBlackList(@PathVariable("id") Int return ResponseEntity.ok(skillCategory); } - - @GetMapping(value = "/blacklist") - public ResponseEntity> getAllBlacklistedCategoryIds() { - List blacklisted = skillCategoryRepository.findAllByBlacklistedTrue(); - List ids = blacklisted.stream().map(SkillCategory::getId).collect(Collectors.toList()); - return ResponseEntity.ok(ids); - } - private SkillCategory getCategory(Integer categoryId) { return skillCategoryRepository.findById(categoryId) .orElseThrow(() -> SkillServiceException.categoryNotFound(categoryId)); diff --git a/src/main/java/de/hbt/power/controller/SkillController.java b/src/main/java/de/hbt/power/controller/SkillController.java index e6fdd4c..521db81 100644 --- a/src/main/java/de/hbt/power/controller/SkillController.java +++ b/src/main/java/de/hbt/power/controller/SkillController.java @@ -16,7 +16,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Set; @@ -31,11 +30,6 @@ */ @RestController() @RequestMapping("/skill") -/* -@CrossOrigin(origins = "*", - methods = {RequestMethod.PUT, RequestMethod.GET, RequestMethod.PATCH, RequestMethod.POST, RequestMethod.DELETE}, - allowedHeaders = {"origin", "content-type", "accept", "authorization", "X-Requested-With"}, - allowCredentials = "true")*/ @CrossOrigin @Log4j2 public class SkillController { @@ -94,26 +88,6 @@ public ResponseEntity moveSkill(@PathVariable("id") Integer skillId, @Pat return ResponseEntity.ok(skill); } - - @ApiOperation(value = "Returns all skill IDs", response = Integer.class, responseContainer = "List") - @GetMapping - public ResponseEntity> getAllSkillIds() { - final List result = new ArrayList<>(); - skillRepository.findAll().forEach(skill -> result.add(skill.getId())); - return ResponseEntity.ok(result); - } - - - @ApiOperation(value = "Updates a skill", response = Skill.class) - @PutMapping("/{id}") - public ResponseEntity updateSkill(@PathVariable Integer id, @RequestBody Skill skill) { - Skill s = requireSkill(id); - skill.setId(s.getId()); - skillRepository.save(s); - return ResponseEntity.ok().build(); - } - - @ApiOperation(value = "Searches and returns a skill by qualifier", response = Skill.class) @GetMapping("/byName") public ResponseEntity findSkillByQualifier(@RequestParam("qualifier") String qualifier) { @@ -134,22 +108,14 @@ public ResponseEntity findSkillByQualifier(@RequestParam("qualifier") Str @ApiOperation(value = "Fuzzy search for skill names", response = String.class, responseContainer = "List") @GetMapping(value = "/search") public ResponseEntity> searchSkill(@RequestParam("searchterm") String searchTerm, @RequestParam Integer maxResults) { - if (maxResults == null) maxResults = DEFAULT_MAX_RESULTS; + if (maxResults == null) { + maxResults = DEFAULT_MAX_RESULTS; + } List suggestions = skillSearcherService.searchSkill(searchTerm, maxResults); return ResponseEntity.ok(suggestions); } - @ApiOperation(value = "Attempty to automatically group a skill into a category", response = Skill.class) - @PatchMapping("/{id}") - public ResponseEntity categorizeSkill(@PathVariable Integer id) { - Skill responseSkill = requireSkill(id); - log.info("Categorizing " + responseSkill.toString()); - responseSkill = categoryService.categorizeSkill(responseSkill); - return ResponseEntity.ok(responseSkill); - } - - /** * Returns the category for the requested SkillId, categorizes the Skill if no SkillCategory was set before. * @@ -159,12 +125,10 @@ public ResponseEntity categorizeSkill(@PathVariable Integer id) { @PostMapping public ResponseEntity updateAndGetCategory(@RequestParam("qualifier") String qualifier) { Skill skill = skillRepository.findOneByQualifier(qualifier) - .orElseGet(() -> skillService.createSkill(qualifier)); - if (skill.getCategory() == null) { - log.info("Categorizing " + skill.toString()); - skill = categoryService.categorizeSkill(skill); - } - skillRepository.save(skill); + .orElseGet(() -> { + Skill toCreate = Skill.of(qualifier); + return skillService.createSkillInCategory(toCreate, categoryService.getOther()); + }); return ResponseEntity.ok(skill.getCategory()); } @@ -185,7 +149,7 @@ public ResponseEntity createSkillInCategory(@RequestBody Skill skill, @Pa if (concurrent.isPresent()) { throw SkillServiceException.skillAlreadyExists(concurrent.get()); } - log.info("Creating " + skill.toString() + " in " + skillCategory.toString()); + log.info("Creating " + skill + " in " + skillCategory.toString()); skill.setId(null); skillService.createSkillInCategory(skill, skillCategory); return ResponseEntity.ok(skill); @@ -194,7 +158,7 @@ public ResponseEntity createSkillInCategory(@RequestBody Skill skill, @Pa @ApiOperation(value = "Permanently deletes a skill") @DeleteMapping("/{id}") - public ResponseEntity deleteSkill(@PathVariable("id") Integer skillId) { + public ResponseEntity deleteSkill(@PathVariable("id") Integer skillId) { skillRepository.findById(skillId) .map(peek(s -> log.info("Deleting skill " + s))) .ifPresent(skillRepository::delete); @@ -231,7 +195,7 @@ public ResponseEntity> addVersion(@PathVariable("id") Integer skillI @ApiOperation(value = "Deletes a version from a skill") @DeleteMapping("{id}/version") - public ResponseEntity deleteVersion(@PathVariable("id") Integer skillId, @RequestBody String version) { + public ResponseEntity deleteVersion(@PathVariable("id") Integer skillId, @RequestBody String version) { Skill skill = requireSkill(skillId); skillService.deleteVersion(skill, version); return ResponseEntity.ok().build(); @@ -242,10 +206,4 @@ public ResponseEntity deleteVersion(@PathVariable("id") Integer skillId, @Reques public ResponseEntity getTree() { return ResponseEntity.ok(skillTreeMappingService.buildSkillTree()); } - - @ApiOperation(value = "Returns a model of the skill tree. Returned value is the root node.", response = TCategoryNode.class) - @GetMapping("/tree/debug") - public ResponseEntity getTreeDebug() { - return ResponseEntity.ok(skillTreeMappingService.buildSkillTreeDebug()); - } } diff --git a/src/main/java/de/hbt/power/repo/SkillCategoryRepository.java b/src/main/java/de/hbt/power/repo/SkillCategoryRepository.java index 323aa6b..dc7d165 100644 --- a/src/main/java/de/hbt/power/repo/SkillCategoryRepository.java +++ b/src/main/java/de/hbt/power/repo/SkillCategoryRepository.java @@ -1,7 +1,6 @@ package de.hbt.power.repo; import de.hbt.power.model.SkillCategory; -import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,12 +11,6 @@ public interface SkillCategoryRepository extends JpaRepository { Optional findOneByQualifier(String qualifier); - List findAllByCategoryIsNull(); - List findAllByCategory(SkillCategory skillCategory); - List findAllByBlacklistedTrue(); - List findTop10ById(Integer id); - List findFirst10ByOrderById(); - } diff --git a/src/main/java/de/hbt/power/repo/SkillRepository.java b/src/main/java/de/hbt/power/repo/SkillRepository.java index f5e01fc..cd0b912 100644 --- a/src/main/java/de/hbt/power/repo/SkillRepository.java +++ b/src/main/java/de/hbt/power/repo/SkillRepository.java @@ -2,7 +2,6 @@ import de.hbt.power.model.Skill; import de.hbt.power.model.SkillCategory; -import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; @@ -15,18 +14,8 @@ public interface SkillRepository extends JpaRepository, CrudRepository { Optional findOneByQualifier(String qualifier); - Optional getByQualifiersContaining(String localizedQualifiers); - - List findAllByCategory_Id(Integer categoryId); - - List findAllByCategory(SkillCategory category); - void deleteAllByCategory(SkillCategory category); - List findTop100ById(Integer id); - - List findFirst50ByOrderById(); - @Query("select s from Skill s WHERE not s.category is null") List findForTree(); } diff --git a/src/main/java/de/hbt/power/service/CategoryService.java b/src/main/java/de/hbt/power/service/CategoryService.java index ac51101..8e924f9 100644 --- a/src/main/java/de/hbt/power/service/CategoryService.java +++ b/src/main/java/de/hbt/power/service/CategoryService.java @@ -1,7 +1,6 @@ package de.hbt.power.service; import de.hbt.power.exception.SkillServiceException; -import de.hbt.power.model.Skill; import de.hbt.power.model.SkillCategory; import de.hbt.power.repo.SkillCategoryRepository; import de.hbt.power.repo.SkillRepository; @@ -92,12 +91,9 @@ public void setIsDisplay(SkillCategory skillCategory, Boolean isDisplay) { } - public Skill categorizeSkill(Skill toCategorize) { - // Skill Provider has been removed, for now, we are simply assuming 'Other' - SkillCategory other = skillCategoryRepository.findOneByQualifier(OTHER_CATEGORY_NAME) + public SkillCategory getOther() { + return skillCategoryRepository.findOneByQualifier(OTHER_CATEGORY_NAME) .orElseThrow(() -> new RuntimeException("Category 'Other' is missing. This should not happen!")); - toCategorize.setCategory(other); - return toCategorize; } public SkillCategory createSkillCategory(SkillCategory category, Integer parentId) { diff --git a/src/main/java/de/hbt/power/service/SkillService.java b/src/main/java/de/hbt/power/service/SkillService.java index 1a15ff2..c0ffcbc 100644 --- a/src/main/java/de/hbt/power/service/SkillService.java +++ b/src/main/java/de/hbt/power/service/SkillService.java @@ -29,13 +29,6 @@ public Skill moveSkillToCategory(Skill toMove, SkillCategory newParent) { return toMove; } - public Skill createSkill(String name) { - Skill skill = new Skill(); - skill.setCustom(true); - skill.setQualifier(name); - return skillRepository.save(skill); - } - @Transactional public Skill createSkillInCategory(Skill skill, SkillCategory skillCategory) { skill.setCustom(true); diff --git a/src/main/java/de/hbt/power/service/SkillTreeMappingService.java b/src/main/java/de/hbt/power/service/SkillTreeMappingService.java index 8c69593..99abf2e 100644 --- a/src/main/java/de/hbt/power/service/SkillTreeMappingService.java +++ b/src/main/java/de/hbt/power/service/SkillTreeMappingService.java @@ -32,10 +32,6 @@ public TCategoryNode buildSkillTree() { return buildSkillTree(skillCategoryRepository.findAll(), skillRepository.findForTree()); } - public TCategoryNode buildSkillTreeDebug() { - return buildSkillTree(skillCategoryRepository.findAll(), skillRepository.findAll()); - } - public TCategoryNode buildSkillTree(List categories, List skills) { log.info("categories: " + categories.size() + " skills: " + skills.size()); return new SkillTreeMapper(categories, skills).map(); diff --git a/src/test/java/de/hbt/power/service/CategoryServiceIntegrationTest.java b/src/test/java/de/hbt/power/service/CategoryServiceIntegrationTest.java index 185b815..3c898e6 100644 --- a/src/test/java/de/hbt/power/service/CategoryServiceIntegrationTest.java +++ b/src/test/java/de/hbt/power/service/CategoryServiceIntegrationTest.java @@ -63,14 +63,6 @@ public void setUp() { skillToTest.setQualifier("Test"); } - @Test - @DirtiesContext - public void testCategorizeSkill() { - skillCategoryRepository.save(SkillCategory.builder().qualifier("Other").build()); - Skill result = categoryService.categorizeSkill(skillToTest); - assertThat(result.getCategory().getQualifier()).isEqualTo("Other"); - } - @Test @DirtiesContext @Transactional diff --git a/src/test/java/de/hbt/power/service/SkillSearcherService_ExpectedResultITest.java b/src/test/java/de/hbt/power/service/SkillSearcherService_ExpectedResultITest.java index 9d7f498..55ea643 100644 --- a/src/test/java/de/hbt/power/service/SkillSearcherService_ExpectedResultITest.java +++ b/src/test/java/de/hbt/power/service/SkillSearcherService_ExpectedResultITest.java @@ -19,17 +19,14 @@ @ActiveProfiles("test") public class SkillSearcherService_ExpectedResultITest { - @Autowired - private SkillService skillService; - @Autowired private SkillRepository skillRepository; @Autowired private SkillSearcherService skillSearcherService; - private Skill persistentSkill(String name) { - return skillService.createSkill(name); + private void persistentSkill(String name) { + skillRepository.save(Skill.of(name)); } @Test diff --git a/src/test/java/de/hbt/power/service/SkillServiceTest.java b/src/test/java/de/hbt/power/service/SkillServiceTest.java index f54f132..6f5c950 100644 --- a/src/test/java/de/hbt/power/service/SkillServiceTest.java +++ b/src/test/java/de/hbt/power/service/SkillServiceTest.java @@ -13,7 +13,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.HashSet; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +32,7 @@ public class SkillServiceTest { private SkillService skillService; @Test - public void moveSkillToCategory() throws Exception { + public void moveSkillToCategory() { SkillCategory category1 = SkillCategory.of("Category1"); skillCategoryRepository.save(category1); SkillCategory category2 = SkillCategory.of("Category2"); @@ -51,10 +50,9 @@ public void moveSkillToCategory() throws Exception { * Creates a custom skill; Makes sure that the skill is in the db, has the correct * parent and has custom flag set to true * - * @throws Exception foo bar */ @Test - public void createSkillInCategory() throws Exception { + public void createSkillInCategory() { SkillCategory skillCategory = SkillCategory.of("Bla Blub"); skillCategoryRepository.save(skillCategory); @@ -68,13 +66,4 @@ public void createSkillInCategory() throws Exception { assertThat(retrieved.isCustom()).isTrue(); } - @Test - public void shouldCreateSkill() { - Skill skill = skillService.createSkill("Java5001"); - assertThat(skill.isCustom()).isTrue(); - assertThat(skill.getQualifier()).isEqualTo("Java5001"); - Optional persistent = skillRepository.findOneByQualifier("Java5001"); - assertThat(persistent).isPresent(); - } - -} \ No newline at end of file +}