UCSBOrganizationController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBOrganization;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository;
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 jakarta.validation.Valid;
24
25
@Tag(name = "UCSBOrganization")
26
@RequestMapping("/api/ucsborganization")
27
@RestController
28
@Slf4j
29
30
public class UCSBOrganizationController extends ApiController {
31
32
    @Autowired
33
    UCSBOrganizationRepository ucsbOrganizationRepository;
34
35
    /**
36
     * THis method returns a list of all ucsborganizations.
37
     * @return a list of all ucsborganizations
38
     */
39
    @Operation(summary= "List all ucsb organizations")
40
    @PreAuthorize("hasRole('ROLE_USER')")
41
    @GetMapping("/all")
42
    public Iterable<UCSBOrganization> allOrgs() {
43
        Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll();
44 1 1. allOrgs : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrgs → KILLED
        return orgs;
45
    }
46
47
48
    /**
49
     * This method returns a single diningcommons.
50
     * @param orgCode orgCode of the diningcommons
51
     * @return a single diningcommons
52
     */
53
    @Operation(summary= "Get a single organization")
54
    @PreAuthorize("hasRole('ROLE_USER')")
55
    @GetMapping("")
56
    public UCSBOrganization getById(
57
            @Parameter(name="orgCode") @RequestParam String orgCode) {
58
        UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode)
59 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
60
61 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
        return org;
62
    }
63
64
    /**
65
     * This method creates a new organization. Accessible only to users with the role "ROLE_ADMIN".
66
     * @param orgCode code of the organization
67
     * @param orgTranslationShort shortened translation of org name
68
     * @param orgTranslation full org name
69
     * @param inactive whether the org is active or not
70
     * @return the saved organization
71
     */
72
    @Operation(summary= "Create a new organization")
73
    @PreAuthorize("hasRole('ROLE_ADMIN')")
74
    @PostMapping("/post")
75
    public UCSBOrganization postOrgs(
76
        @Parameter(name="orgCode") @RequestParam String orgCode,
77
        @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort,
78
        @Parameter(name="orgTranslation") @RequestParam String orgTranslation,
79
        @Parameter(name="inactive") @RequestParam boolean inactive
80
        )
81
        {
82
83
        UCSBOrganization org = new UCSBOrganization();
84 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
        org.setOrgCode(orgCode);
85 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        org.setOrgTranslationShort(orgTranslationShort);
86 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        org.setOrgTranslation(orgTranslation);
87 1 1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        org.setInactive(inactive);
88
89
        UCSBOrganization savedOrg = ucsbOrganizationRepository.save(org);
90
91 1 1. postOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrgs → KILLED
        return savedOrg;
92
    }
93
94
    /**
95
     * Delete a organization. Accessible only to users with the role "ROLE_ADMIN".
96
     * @param orgCode orgCode of the commons
97
     * @return a message indiciating the organization was deleted
98
     */
99
    @Operation(summary= "Delete a UCSBOrganization")
100
    @PreAuthorize("hasRole('ROLE_ADMIN')")
101
    @DeleteMapping("")
102
    public Object deleteOrganization(
103
            @Parameter(name="orgCode") @RequestParam String orgCode) {
104
        UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode)
105 1 1. lambda$deleteOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
106
107 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
        ucsbOrganizationRepository.delete(org);
108 1 1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrganization → KILLED
        return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode));
109
    }
110
111
    /**
112
     * Update a single organization. Accessible only to users with the role "ROLE_ADMIN".
113
     * @param orgCode code of the organization
114
     * @param incoming the new organization contents
115
     * @return the updated organization object
116
     */
117
    @Operation(summary= "Update a single organization")
118
    @PreAuthorize("hasRole('ROLE_ADMIN')")
119
    @PutMapping("")
120
    public UCSBOrganization updateOrganization(
121
            @Parameter(name="orgCode") @RequestParam String orgCode,
122
            @RequestBody @Valid UCSBOrganization incoming) {
123
124
        UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode)
125 1 1. lambda$updateOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
126
127
128 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
        org.setOrgCode(incoming.getOrgCode());
129 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        org.setOrgTranslationShort(incoming.getOrgTranslationShort());
130 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        org.setOrgTranslation(incoming.getOrgTranslation());
131 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        org.setInactive(incoming.getInactive());
132
133
        ucsbOrganizationRepository.save(org);
134
135 1 1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED
        return org;
136
    }
137
138
}

Mutations

44

1.1
Location : allOrgs
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::allOrgs → KILLED

59

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

61

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

84

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/UCSBOrganization::setOrgCode → 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()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

86

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/UCSBOrganization::setOrgTranslation → KILLED

87

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/UCSBOrganization::setInactive → KILLED

91

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

105

1.1
Location : lambda$deleteOrganization$1
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_org_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$1 → KILLED

107

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

108

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

125

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

128

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

129

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

130

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

131

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

135

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

Active mutators

Tests examined


Report generated by PIT 1.17.0