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 UCSBDates */
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
   * List all UCSB Organizations
33
   *
34
   * @return an iterable of UCSBOrganization
35
   */
36
  @Operation(summary = "List all organizations")
37
  @PreAuthorize("hasRole('ROLE_USER')")
38
  @GetMapping("/all")
39
  public Iterable<UCSBOrganization> allUCSBOrganizations() {
40
    Iterable<UCSBOrganization> organizations = ucsbOrganizationRepository.findAll();
41 1 1. allUCSBOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allUCSBOrganizations → KILLED
    return organizations;
42
  }
43
44
  /**
45
   * This method returns a single organization.
46
   *
47
   * @param orgCode code of the organization
48
   * @return a single organization
49
   */
50
  @Operation(summary = "Get a single organization")
51
  @PreAuthorize("hasRole('ROLE_USER')")
52
  @GetMapping("")
53
  public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) {
54
    UCSBOrganization organization =
55
        ucsbOrganizationRepository
56
            .findById(orgCode)
57 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));
58
59 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return organization;
60
  }
61
62
  /**
63
   * Create a new ucsb organization
64
   *
65
   * @param orgCode the code of the organization
66
   * @param orgTranslationShort shortened version of the organization
67
   * @param orgTranslation organization name
68
   * @param inactive if the organization is still active or not
69
   * @return the saved ucsbdate
70
   */
71
  @Operation(summary = "Create a new organization")
72
  @PreAuthorize("hasRole('ROLE_ADMIN')")
73
  @PostMapping("/post")
74
  public UCSBOrganization postUCSBDate(
75
      @Parameter(name = "orgCode") @RequestParam String orgCode,
76
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
77
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
78
      @Parameter(name = "inactive") @RequestParam boolean inactive) {
79
80
    UCSBOrganization ucsbOrganization = new UCSBOrganization();
81 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    ucsbOrganization.setOrgCode(orgCode);
82 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    ucsbOrganization.setOrgTranslationShort(orgTranslationShort);
83 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    ucsbOrganization.setOrgTranslation(orgTranslation);
84 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    ucsbOrganization.setInactive(inactive);
85
86
    UCSBOrganization savedUcsbOrganization = ucsbOrganizationRepository.save(ucsbOrganization);
87
88 1 1. postUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postUCSBDate → KILLED
    return savedUcsbOrganization;
89
  }
90
91
  /**
92
   * Delete an organization. Accessible only to users with the role "ROLE_ADMIN".
93
   *
94
   * @param orgCode code of the organization
95
   * @return a message indiciating the commons was deleted
96
   */
97
  @Operation(summary = "Delete an organization")
98
  @PreAuthorize("hasRole('ROLE_ADMIN')")
99
  @DeleteMapping("")
100
  public Object deleteCommons(@Parameter(name = "orgCode") @RequestParam String orgCode) {
101
    UCSBOrganization organization =
102
        ucsbOrganizationRepository
103
            .findById(orgCode)
104 1 1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteCommons$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
105 1 1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(organization);
106 1 1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteCommons → KILLED
    return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode));
107
  }
108
109
  /**
110
   * Update a single organization. Accessible only to users with the role "ROLE_ADMIN".
111
   *
112
   * @param orgCode code of the organization
113
   * @param incoming the new organization contents
114
   * @return the updated organization object
115
   */
116
  @Operation(summary = "Update a single organization")
117
  @PreAuthorize("hasRole('ROLE_ADMIN')")
118
  @PutMapping("")
119
  public UCSBOrganization updateOrganization(
120
      @Parameter(name = "orgCode") @RequestParam String orgCode,
121
      @RequestBody @Valid UCSBOrganization incoming) {
122
123
    UCSBOrganization organization =
124
        ucsbOrganizationRepository
125
            .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 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    organization.setOrgTranslationShort(incoming.getOrgTranslationShort());
129 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    organization.setOrgTranslation(incoming.getOrgTranslation());
130 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    organization.setInactive(incoming.getInactive());
131
132
    ucsbOrganizationRepository.save(organization);
133
134 1 1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED
    return organization;
135
  }
136
}

Mutations

41

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

57

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

59

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

81

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

82

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

83

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

84

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

88

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

104

1.1
Location : lambda$deleteCommons$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$deleteCommons$1 → KILLED

105

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

106

1.1
Location : deleteCommons
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::deleteCommons → 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_commons_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$2 → KILLED

128

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

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::setOrgTranslation → 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::setInactive → 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()]
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