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 jakarta.validation.Valid;
10
import lombok.extern.slf4j.Slf4j;
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
/** This is a REST controller for UCSBOrganization */
23
@Tag(name = "UCSBOrganization")
24
@RequestMapping("/api/ucsborganization")
25
@RestController
26
@Slf4j
27
public class UCSBOrganizationController extends ApiController {
28
29
  @Autowired UCSBOrganizationRepository ucsbOrganizationRepository;
30
31
  /**
32
   * THis method returns a list of all UCSBOrganization.
33
   *
34
   * @return a list of all UCSBOrganizations
35
   */
36
  @Operation(summary = "List all ucsb organizations")
37
  @PreAuthorize("hasRole('ROLE_USER')")
38
  @GetMapping("/all")
39
  public Iterable<UCSBOrganization> allorgss() {
40
    Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll();
41 1 1. allorgss : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allorgss → KILLED
    return orgs;
42
  }
43
44
  /**
45
   * This method creates a new org. Accessible only to users with the role "ROLE_ADMIN".
46
   *
47
   * @param orgCode orgCode of the organization (e.g. ZPR)
48
   * @param orgTranslationShort short name of the organization
49
   * @param orgTranslation full name of the organization
50
   * @param inactive whether or not the organization is inactive
51
   * @return the saved organization
52
   */
53
  @Operation(summary = "Create a new organization")
54
  @PreAuthorize("hasRole('ROLE_ADMIN')")
55
  @PostMapping("/post")
56
  public UCSBOrganization postOrganization(
57
      @Parameter(name = "orgCode", description = "Organization orgCode, e.g. ZPR") @RequestParam
58
          String orgCode,
59
      @Parameter(name = "orgTranslationShort", description = "Short name, e.g. ZETA PHI RHO")
60
          @RequestParam
61
          String orgTranslationShort,
62
      @Parameter(name = "orgTranslation", description = "Full name, e.g. ZETA PHI RHO")
63
          @RequestParam
64
          String orgTranslation,
65
      @Parameter(name = "inactive", description = "true if the organization is inactive")
66
          @RequestParam
67
          boolean inactive) {
68
69
    UCSBOrganization org = new UCSBOrganization();
70 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    org.setOrgCode(orgCode);
71 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(orgTranslationShort);
72 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(orgTranslation);
73 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(inactive);
74
75
    UCSBOrganization savedOrg = ucsbOrganizationRepository.save(org);
76 1 1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED
    return savedOrg;
77
  }
78
79
  /**
80
   * PUTTTTT Update a single UCSB organization. Accessible only to users with the role "ROLE_ADMIN".
81
   *
82
   * @param orgCode orgCode of the organization to update
83
   * @param incoming the new values for the organization
84
   * @return the updated organization
85
   */
86
  @Operation(summary = "Update a single UCSB organization")
87
  @PreAuthorize("hasRole('ROLE_ADMIN')")
88
  @PutMapping("")
89
  public UCSBOrganization updateOrganization(
90
      @Parameter(name = "orgCode", description = "Code of the organization to update, e.g. ZPR")
91
          @RequestParam
92
          String orgCode,
93
      @RequestBody @Valid UCSBOrganization incoming) {
94
95
    UCSBOrganization org =
96
        ucsbOrganizationRepository
97
            .findById(orgCode)
98 1 1. lambda$updateOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
99
100 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(incoming.getOrgTranslationShort());
101 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(incoming.getOrgTranslation());
102 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(incoming.getInactive());
103
104
    ucsbOrganizationRepository.save(org);
105
106 1 1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED
    return org;
107
  }
108
109
  /**
110
   * This method returns a single UCSB organization. GET
111
   *
112
   * @param orgCode orgCode of the organization
113
   * @return a single UCSB organization
114
   */
115
  @Operation(summary = "Get a single UCSB organization")
116
  @PreAuthorize("hasRole('ROLE_USER')")
117
  @GetMapping("")
118
  public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) {
119
    UCSBOrganization org =
120
        ucsbOrganizationRepository
121
            .findById(orgCode)
122 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));
123
124 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return org;
125
  }
126
127
  // DELETE
128
  /**
129
   * Delete an organization. Accessible only to users with the role "ROLE_ADMIN".
130
   *
131
   * @param orgCode code of the organization to delete
132
   * @return a message indiciating the organization was deleted
133
   */
134
  @Operation(summary = "Delete a UCSBOrganization")
135
  @PreAuthorize("hasRole('ROLE_ADMIN')")
136
  @DeleteMapping("")
137
  public Object deleteOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) {
138
    UCSBOrganization org =
139
        ucsbOrganizationRepository
140
            .findById(orgCode)
141 1 1. lambda$deleteOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
142
143 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(org);
144 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));
145
  }
146
}

Mutations

41

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

70

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

71

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

72

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

73

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

76

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

98

1.1
Location : lambda$updateOrganization$0
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$0 → KILLED

100

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

101

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

102

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

106

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

122

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

124

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

141

1.1
Location : lambda$deleteOrganization$0
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$0 → KILLED

143

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

144

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

Active mutators

Tests examined


Report generated by PIT 1.30.0 support