UCSBOrganizationsController.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 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
public class UCSBOrganizationsController extends ApiController {
34
35
    @Autowired
36
    UCSBOrganizationsRepository ucsbOrganizationsRepository;
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<UCSBOrganizations> allOrganizations() {
46
        Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll();
47 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED
        return organizations;
48
    }
49
50
    /**
51
     * This method returns a single UCSBOrganizations.
52
     * @param orgcode orgcode of the UCSBOrganizations
53
     * @return a single UCSBOrganizations
54
     */
55
    @Operation(summary= "Get a single organization")
56
    @PreAuthorize("hasRole('ROLE_USER')")
57
    @GetMapping("")
58
    public UCSBOrganizations getById(
59
            @Parameter(name="orgcode") @RequestParam String orgcode) {
60
        UCSBOrganizations organizations = ucsbOrganizationsRepository.findById(orgcode)
61 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgcode));
62
63 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getById → KILLED
        return organizations;
64
    }
65
66
    /**
67
     * This method creates a new UCSBOrganizations. Accessible only to users with the role "ROLE_ADMIN".
68
     * @param orgcode orgcode of the UCSBOrganizations
69
     * @param orgTranslationShort orgTranslationShort of the UCSBOrganizations
70
     * @param orgTranslation orgTranslation of the UCSBOrganizations
71
     * @param inactive whether or not the UCSBOrganizations are inactive
72
     */
73
    @Operation(summary= "Create a new organization")
74
    @PreAuthorize("hasRole('ROLE_ADMIN')")
75
    @PostMapping("/post")
76
    public UCSBOrganizations postOrganizations(
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
        UCSBOrganizations organizations = new UCSBOrganizations();
84 1 1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgcode → KILLED
        organizations.setOrgcode(orgcode);
85 1 1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
        organizations.setOrgTranslationShort(orgTranslationShort);
86 1 1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
        organizations.setOrgTranslation(orgTranslation);
87 1 1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
        organizations.setInactive(inactive);
88
89
        UCSBOrganizations saveOrganizations = ucsbOrganizationsRepository.save(organizations);
90
91 1 1. postOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postOrganizations → KILLED
        return saveOrganizations;
92
    }
93
    /**
94
     * Delete a diningcommons. Accessible only to users with the role "ROLE_ADMIN".
95
     * @param orgcode code of the commons
96
     * @return a message indiciating the commons was deleted
97
     */
98
    @Operation(summary= "Delete a UCSBOrganizations")
99
    @PreAuthorize("hasRole('ROLE_ADMIN')")
100
    @DeleteMapping("")
101
    public Object deleteOrganizations(
102
            @Parameter(name="orgcode") @RequestParam String orgcode) {
103
        UCSBOrganizations organization = ucsbOrganizationsRepository.findById(orgcode)
104 1 1. lambda$deleteOrganizations$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteOrganizations$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgcode));
105
106 1 1. deleteOrganizations : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED
        ucsbOrganizationsRepository.delete(organization);
107 1 1. deleteOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteOrganizations → KILLED
        return genericMessage("UCSBOrganizations with id %s deleted".formatted(orgcode));
108
    }
109
    /**
110
     * Update a single diningcommons. Accessible only to users with the role "ROLE_ADMIN".
111
     * @param orgcode code of the diningcommons
112
     * @param incoming the new commons contents
113
     * @return the updated commons object
114
     */
115
    @Operation(summary= "Update a single organization")
116
    @PreAuthorize("hasRole('ROLE_ADMIN')")
117
    @PutMapping("")
118
    public UCSBOrganizations updateOrganizations(
119
            @Parameter(name="orgcode") @RequestParam String orgcode,
120
            @RequestBody @Valid UCSBOrganizations incoming) {
121
122
        UCSBOrganizations organizations = ucsbOrganizationsRepository.findById(orgcode)
123 1 1. lambda$updateOrganizations$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateOrganizations$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgcode));
124
125
126 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgcode → KILLED
        organizations.setOrgcode(incoming.getOrgcode());  
127 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
        organizations.setOrgTranslationShort(incoming.getOrgTranslationShort());
128 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
        organizations.setOrgTranslation(incoming.getOrgTranslation());
129 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
        organizations.setInactive(incoming.getInactive());
130
131
        ucsbOrganizationsRepository.save(organizations);
132
133 1 1. updateOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateOrganizations → KILLED
        return organizations;
134
    }
135
}

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

61

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

63

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

84

1.1
Location : postOrganizations
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_organizations()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgcode → KILLED

85

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

86

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

87

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

91

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

104

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

106

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

107

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

123

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

126

1.1
Location : updateOrganizations
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_edit_an_existing_organizations()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgcode → KILLED

127

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

128

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

129

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

133

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

Active mutators

Tests examined


Report generated by PIT 1.17.0