UCSBOrganizationsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import edu.ucsb.cs156.example.entities.UCSBOrganizations;
5
import edu.ucsb.cs156.example.repositories.UCSBOrganizationsRepository;
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
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.http.HttpStatus;
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
import org.springframework.web.server.ResponseStatusException;
22
23
/** This is a REST controller for UCSBOrganizations */
24
@Tag(name = "UCSBOrganizations")
25
@RequestMapping("/api/ucsborganizations")
26
@RestController
27
@Slf4j
28
public class UCSBOrganizationsController extends ApiController {
29
30
  @Autowired UCSBOrganizationsRepository ucsbOrganizationsRepository;
31
32
  /**
33
   * List all UCSB organizations
34
   *
35
   * @return an iterable of UCSBOrganizations
36
   */
37
  @Operation(summary = "List all UCSB organizations")
38
  @PreAuthorize("hasRole('ROLE_USER')")
39
  @GetMapping("/all")
40
  public Iterable<UCSBOrganizations> allUCSBOrganizations() {
41
    Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll();
42 1 1. allUCSBOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allUCSBOrganizations → KILLED
    return organizations;
43
  }
44
45
  /**
46
   * Get a UCSB organization by ID
47
   *
48
   * @param orgCode the organization code
49
   * @return the UCSB organization
50
   */
51
  @Operation(summary = "Get a UCSB organization by ID")
52
  @PreAuthorize("hasRole('ROLE_USER')")
53
  @GetMapping("")
54
  public UCSBOrganizations getUCSBOrganizationById(
55
      @Parameter(name = "orgCode") @RequestParam String orgCode) {
56
57
    UCSBOrganizations organization =
58
        ucsbOrganizationsRepository
59
            .findById(orgCode)
60
            .orElseThrow(
61
                () ->
62 1 1. lambda$getUCSBOrganizationById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getUCSBOrganizationById$0 → KILLED
                    new ResponseStatusException(
63
                        HttpStatus.NOT_FOUND, "UCSB Organization Not Found"));
64
65 1 1. getUCSBOrganizationById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getUCSBOrganizationById → KILLED
    return organization;
66
  }
67
68
  /**
69
   * Update a UCSB organization
70
   *
71
   * @param orgCode the organization code to update
72
   * @param incoming the updated organization data
73
   * @return the updated organization
74
   */
75
  @Operation(summary = "Update a UCSB organization")
76
  @PreAuthorize("hasRole('ROLE_ADMIN')")
77
  @PutMapping("")
78
  public UCSBOrganizations updateUCSBOrganization(
79
      @Parameter(name = "orgCode") @RequestParam String orgCode,
80
      @RequestBody UCSBOrganizations incoming) {
81
82
    UCSBOrganizations organization =
83
        ucsbOrganizationsRepository
84
            .findById(orgCode)
85
            .orElseThrow(
86
                () ->
87 1 1. lambda$updateUCSBOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateUCSBOrganization$0 → KILLED
                    new ResponseStatusException(
88
                        HttpStatus.NOT_FOUND, "UCSB Organization Not Found"));
89
90 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
    organization.setOrgTranslationShort(incoming.getOrgTranslationShort());
91 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
    organization.setOrgTranslation(incoming.getOrgTranslation());
92 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
    organization.setInactive(incoming.getInactive());
93
94
    UCSBOrganizations savedOrganization = ucsbOrganizationsRepository.save(organization);
95
96 1 1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateUCSBOrganization → KILLED
    return savedOrganization;
97
  }
98
99
  /**
100
   * Create a new UCSB organization
101
   *
102
   * @param orgCode the organization code
103
   * @param orgTranslationShort the short organization name
104
   * @param orgTranslation the full organization name
105
   * @param inactive whether the organization is inactive
106
   * @return the saved UCSB organization
107
   */
108
  @Operation(summary = "Create a new UCSB organization")
109
  @PreAuthorize("hasRole('ROLE_ADMIN')")
110
  @PostMapping("/post")
111
  public UCSBOrganizations postUCSBOrganization(
112
      @Parameter(name = "orgCode") @RequestParam String orgCode,
113
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
114
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
115
      @Parameter(name = "inactive") @RequestParam boolean inactive)
116
      throws JsonProcessingException {
117
118
    UCSBOrganizations organization = new UCSBOrganizations();
119 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED
    organization.setOrgCode(orgCode);
120 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
    organization.setOrgTranslationShort(orgTranslationShort);
121 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
    organization.setOrgTranslation(orgTranslation);
122 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
    organization.setInactive(inactive);
123
124
    UCSBOrganizations savedOrganization = ucsbOrganizationsRepository.save(organization);
125
126 1 1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postUCSBOrganization → KILLED
    return savedOrganization;
127
  }
128
129
  /**
130
   * Delete a UCSB organization
131
   *
132
   * @param orgCode the organization code
133
   * @return a confirmation message
134
   */
135
  @Operation(summary = "Delete a UCSB organization")
136
  @PreAuthorize("hasRole('ROLE_ADMIN')")
137
  @DeleteMapping("")
138
  public Object deleteUCSBOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) {
139
140
    UCSBOrganizations organization =
141
        ucsbOrganizationsRepository
142
            .findById(orgCode)
143
            .orElseThrow(
144
                () ->
145 1 1. lambda$deleteUCSBOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteUCSBOrganization$0 → KILLED
                    new ResponseStatusException(
146
                        HttpStatus.NOT_FOUND, "UCSB Organization Not Found"));
147
148 1 1. deleteUCSBOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED
    ucsbOrganizationsRepository.delete(organization);
149
150 1 1. deleteUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteUCSBOrganization → KILLED
    return java.util.Map.of("message", "UCSBOrganizations with id " + orgCode + " deleted");
151
  }
152
}

Mutations

42

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

62

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

65

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

87

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

90

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

91

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

92

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

96

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

119

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

120

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

121

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

122

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

126

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

145

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

148

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

150

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

Active mutators

Tests examined


Report generated by PIT 1.30.0 support