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

Mutations

47

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

70

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

71

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

72

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

73

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

77

1.1
Location : postOrganization
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:an_admin_user_can_post_a_new_ucsborganization()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postOrganization → KILLED

91

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[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/UCSBOrganizationsController::lambda$getById$0 → KILLED

93

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[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/UCSBOrganizationsController::getById → KILLED

107

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

109

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

110

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_delete_an_organization()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteCommons → KILLED

127

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

130

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

131

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

132

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

136

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

Active mutators

Tests examined


Report generated by PIT 1.17.0