UCSBOrganizationController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import edu.ucsb.cs156.example.entities.UCSBOrganization;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository;
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 jakarta.validation.Valid;
11
import lombok.extern.slf4j.Slf4j;
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
/** This is a REST controller for UCSBDates */
24
@Tag(name = "UCSBOrganization")
25
@RequestMapping("/api/ucsborganizations")
26
@RestController
27
@Slf4j
28
public class UCSBOrganizationController extends ApiController {
29
30
  @Autowired UCSBOrganizationRepository ucsbOrganizationRepository;
31
32
  /**
33
   * List all UCSB organizations
34
   *
35
   * @return an iterable of UCSBOrganization
36
   */
37
  @Operation(summary = "List all ucsb organizations")
38
  @PreAuthorize("hasRole('USER')")
39
  @GetMapping("/all")
40
  public Iterable<UCSBOrganization> allUCSBOrganizations() {
41
    Iterable<UCSBOrganization> organizations = ucsbOrganizationRepository.findAll();
42 1 1. allUCSBOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allUCSBOrganizations → KILLED
    return organizations;
43
  }
44
45
  /**
46
   * Get a single organization from its code
47
   *
48
   * @param orgCode code for the organization
49
   * @return a UCSBOrganization
50
   */
51
  @Operation(summary = "Get a single organization")
52
  @PreAuthorize("hasRole('ROLE_USER')")
53
  @GetMapping("")
54
  public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) {
55
    UCSBOrganization ucsbOrganization =
56
        ucsbOrganizationRepository
57
            .findById(orgCode)
58 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));
59
60 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return ucsbOrganization;
61
  }
62
63
  /**
64
   * Create a new organization
65
   *
66
   * @param orgCode organization code
67
   * @param orgTranslationShort the short translation of the organization
68
   * @param orgTranslation the long translation of the organization
69
   * @param inactive true if inactive, false if active
70
   * @return the saved organization
71
   */
72
  @Operation(summary = "Create a new organization")
73
  //  @PreAuthorize("hasRole('ROLE_ADMIN')")
74
  @PreAuthorize("hasRole('ADMIN')")
75
  @PostMapping("/post")
76
  public UCSBOrganization postUCSBOrganization(
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
      throws JsonProcessingException {
82
83
    // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
84
    // See: https://www.baeldung.com/spring-date-parameters
85
86
    log.info("orgCode={}", orgCode);
87
88
    UCSBOrganization ucsbOrganization = new UCSBOrganization();
89 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    ucsbOrganization.setOrgCode(orgCode);
90 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    ucsbOrganization.setOrgTranslationShort(orgTranslationShort);
91 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    ucsbOrganization.setOrgTranslation(orgTranslation);
92 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    ucsbOrganization.setInactive(inactive);
93
94
    UCSBOrganization savedUcsbOrganization = ucsbOrganizationRepository.save(ucsbOrganization);
95
96 1 1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postUCSBOrganization → KILLED
    return savedUcsbOrganization;
97
  }
98
99
  /**
100
   * Delete a UCSBOrganization
101
   *
102
   * @param orgCode the code of the organization to delete
103
   * @return a message indicating the organization was deleted
104
   */
105
  @Operation(summary = "Delete a UCSBOrganization")
106
  @PreAuthorize("hasRole('ROLE_ADMIN')")
107
  @DeleteMapping("")
108
  public Object deleteUCSBOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) {
109
    UCSBOrganization ucsbOrganization =
110
        ucsbOrganizationRepository
111
            .findById(orgCode)
112 1 1. lambda$deleteUCSBOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteUCSBOrganization$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
113
114 1 1. deleteUCSBOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(ucsbOrganization);
115 1 1. deleteUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteUCSBOrganization → KILLED
    return genericMessage("UCSBOrganization with orgCode %s deleted".formatted(orgCode));
116
  }
117
118
  /**
119
   * Update a single organization
120
   *
121
   * @param orgCode code of the organization to update
122
   * @param incoming the new organization
123
   * @return the updated organization object
124
   */
125
  @Operation(summary = "Update a single organization")
126
  @PreAuthorize("hasRole('ROLE_ADMIN')")
127
  @PutMapping("")
128
  public UCSBOrganization updateUCSBOrganization(
129
      @Parameter(name = "orgCode") @RequestParam String orgCode,
130
      @RequestBody @Valid UCSBOrganization incoming) {
131
132
    UCSBOrganization ucsbOrganization =
133
        ucsbOrganizationRepository
134
            .findById(orgCode)
135 1 1. lambda$updateUCSBOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateUCSBOrganization$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
136
137 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    ucsbOrganization.setOrgTranslationShort(incoming.getOrgTranslationShort());
138 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    ucsbOrganization.setOrgTranslation(incoming.getOrgTranslation());
139 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    ucsbOrganization.setInactive(incoming.getInactive());
140
141
    ucsbOrganizationRepository.save(ucsbOrganization);
142
143 1 1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateUCSBOrganization → KILLED
    return ucsbOrganization;
144
  }
145
}

Mutations

42

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

58

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

60

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

89

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

90

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

91

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

92

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

96

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

112

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

114

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

115

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

135

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

137

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

138

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

139

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

143

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

Active mutators

Tests examined


Report generated by PIT 1.30.0 support