UCSBOrganizationController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBOrganizations;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBOrganizationsRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.DeleteMapping;
15
import org.springframework.web.bind.annotation.GetMapping;
16
import org.springframework.web.bind.annotation.PostMapping;
17
import org.springframework.web.bind.annotation.PutMapping;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
23
import com.fasterxml.jackson.core.JsonProcessingException;
24
25
import jakarta.validation.Valid;
26
27
@Tag(name = "UCSBOrganizations")
28
@RequestMapping("/api/ucsborganizations")
29
@RestController
30
@Slf4j
31
public class UCSBOrganizationController extends ApiController{
32
    @Autowired
33
    UCSBOrganizationsRepository ucsbOrganizationsRepository;
34
    /**
35
     * This method returns a list of all ucsborganizations.
36
     * @return a list of all ucsborganizations
37
     */
38
    @Operation(summary= "List all ucsb organizations")
39
    @PreAuthorize("hasRole('ROLE_USER')")
40
    @GetMapping("/all")
41
    public Iterable<UCSBOrganizations> allOrganizations() {
42
        Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll();
43 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED
        return organizations;
44
    }
45
46
    /**
47
     * This method returns a single organization.
48
     * @param orgCode code of the organization
49
     * @return a single organization
50
     */
51
    @Operation(summary= "Get a single organization")
52
    @PreAuthorize("hasRole('ROLE_USER')")
53
    @GetMapping("")
54
    public UCSBOrganizations getById(
55
            @Parameter(name="orgCode") @RequestParam String orgCode) {
56
        UCSBOrganizations org = ucsbOrganizationsRepository.findById(orgCode)
57 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode));
58 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
        return org;
59
    }
60
61
    /**
62
     * This method creates a new organiation. Accessible only to users with the role "ROLE_ADMIN".
63
     * @param orgCode code of the organization
64
     * @param orgTranslationShort short translation of the organization
65
     * @param orgTranslation translation of the organization
66
     * @param inactive whether the organization is inactive
67
     * @return the newly created organization
68
     */
69
    @Operation(summary= "Create a new organization")
70
    @PreAuthorize("hasRole('ROLE_ADMIN')")
71
    @PostMapping("/post")
72
    public UCSBOrganizations postOrgs(
73
        @Parameter(name="orgCode") @RequestParam String orgCode,
74
        @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort,
75
        @Parameter(name="orgTranslation") @RequestParam String orgTranslation,
76
        @Parameter(name="inactive") @RequestParam boolean inactive
77
        )
78
        {
79
        UCSBOrganizations org = new UCSBOrganizations();
80 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED
        org.setOrgCode(orgCode);
81 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
        org.setOrgTranslationShort(orgTranslationShort);
82 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
        org.setOrgTranslation(orgTranslation);
83 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
        org.setInactive(inactive);
84
        UCSBOrganizations savedOrg = ucsbOrganizationsRepository.save(org);
85 1 1. postOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrgs → KILLED
        return savedOrg;
86
    }
87
88
    /**
89
     * Update a single org. Accessible only to users with the role "ROLE_ADMIN".
90
     * @param orgCode the code of the org to update
91
     * @param incoming the new org contents
92
     * @return the updated org object
93
     */
94
    @Operation(summary= "Update a single organization")
95
    @PreAuthorize("hasRole('ROLE_ADMIN')")
96
    @PutMapping("")
97
    public UCSBOrganizations updateOrgs(
98
            @Parameter(name="orgCode") @RequestParam String orgCode,
99
            @RequestBody @Valid UCSBOrganizations incoming) {
100
        UCSBOrganizations org = ucsbOrganizationsRepository.findById(orgCode)
101 1 1. lambda$updateOrgs$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrgs$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode));
102 1 1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED
        org.setOrgCode(incoming.getOrgCode());
103 1 1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
        org.setOrgTranslationShort(incoming.getOrgTranslationShort());
104 1 1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
        org.setOrgTranslation(incoming.getOrgTranslation());
105 1 1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
        org.setInactive(incoming.getInactive());
106
        ucsbOrganizationsRepository.save(org);
107 1 1. updateOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrgs → KILLED
        return org;
108
    }
109
110
    /**
111
     * Delete an organization. Accessible only to users with the role "ROLE_ADMIN".
112
     * @param orgCode code of the organization
113
     * @return a message indiciating the organization was deleted
114
     */
115
    @Operation(summary= "Delete a UCSBOrganization")
116
    @PreAuthorize("hasRole('ROLE_ADMIN')")
117
    @DeleteMapping("")
118
    public Object deleteOrgs(
119
            @Parameter(name="orgCode") @RequestParam String orgCode) {
120
        UCSBOrganizations org = ucsbOrganizationsRepository.findById(orgCode)
121 1 1. lambda$deleteOrgs$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrgs$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode));
122 1 1. deleteOrgs : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED
        ucsbOrganizationsRepository.delete(org);
123 1 1. deleteOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrgs → KILLED
        return genericMessage("UCSBOrganizations with id %s deleted".formatted(orgCode));
124
    }
125
}

Mutations

43

1.1
Location : allOrganizations
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:logged_in_user_can_get_all_ucsborganizations()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED

57

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$0 → KILLED

58

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED

80

1.1
Location : postOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:an_admin_user_can_post_a_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED

81

1.1
Location : postOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:an_admin_user_can_post_a_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED

82

1.1
Location : postOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:an_admin_user_can_post_a_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED

83

1.1
Location : postOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:an_admin_user_can_post_a_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED

85

1.1
Location : postOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:an_admin_user_can_post_a_new_org()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrgs → KILLED

101

1.1
Location : lambda$updateOrgs$1
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_cannot_edit_orgs_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrgs$1 → KILLED

102

1.1
Location : updateOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_edit_an_existing_orgs()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED

103

1.1
Location : updateOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_edit_an_existing_orgs()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED

104

1.1
Location : updateOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_edit_an_existing_orgs()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED

105

1.1
Location : updateOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_edit_an_existing_orgs()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED

107

1.1
Location : updateOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_edit_an_existing_orgs()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrgs → KILLED

121

1.1
Location : lambda$deleteOrgs$2
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_tries_to_delete_non_existant_organizations_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrgs$2 → KILLED

122

1.1
Location : deleteOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_delete_a_organizations()]
removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED

123

1.1
Location : deleteOrgs
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[method:admin_can_delete_a_organizations()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrgs → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0