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

Mutations

46

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

60

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

62

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

85

1.1
Location : postCommons
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

86

1.1
Location : postCommons
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

87

1.1
Location : postCommons
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

88

1.1
Location : postCommons
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

92

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

106

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_commons_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$1 → 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_date()]
removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED

109

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

126

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

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::setOrgCode → 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::setOrgTranslationShort → 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::setOrgTranslation → KILLED

132

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

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()]
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