UCSBOrganizationController.java

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

Mutations

51

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_ucsborganization()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED

65

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

67

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

90

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

91

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

92

1.1
Location : postOrganization
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_organization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED

93

1.1
Location : postOrganization
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_organization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED

97

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

111

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

113

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_an_organization()]
removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED

114

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

131

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

134

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

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

136

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

140

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