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 UCSBOrganization */
24
@Tag(name = "UCSBOrganization")
25
@RequestMapping("/api/ucsborganization")
26
@RestController
27
@Slf4j
28
public class UCSBOrganizationController extends ApiController {
29
30
  @Autowired UCSBOrganizationRepository ucsbOrganizationRepository;
31
32
  /**
33
   * List all UCSB dates
34
   *
35
   * @return an iterable of UCSBDate
36
   */
37
  @Operation(summary = "List all ucsb organizations")
38
  @PreAuthorize("hasRole('ROLE_USER')")
39
  @GetMapping("/all")
40
  public Iterable<UCSBOrganization> allUCSBOrganization() {
41
    Iterable<UCSBOrganization> ucsbOrganization = ucsbOrganizationRepository.findAll();
42 1 1. allUCSBOrganization : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allUCSBOrganization → KILLED
    return ucsbOrganization;
43
  }
44
45
  /**
46
   * Create a new UCSBOrganization
47
   *
48
   * @param orgCode the UCSBOrganization orgCode
49
   * @param orgTranslationShort the UCSBOrganization orgTranslationShort
50
   * @param orgTranslation the UCSBOrganization orgTranslation
51
   * @param inactive the UCSBOrganization inactive
52
   * @return the saved UCSBOrganization
53
   */
54
  @Operation(summary = "Create a new UCSBOrganization")
55
  @PreAuthorize("hasRole('ROLE_ADMIN')")
56
  @PostMapping("/post")
57
  public UCSBOrganization postUCSBOrganization(
58
      @Parameter(name = "orgCode") @RequestParam String orgCode,
59
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
60
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
61
      @Parameter(name = "inactive") @RequestParam Boolean inactive)
62
      // @Parameter(
63
      // name = "UCSBOrganizationTime",
64
      // description =
65
      // "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SSZ; see
66
      // https://en.wikipedia.org/wiki/ISO_8601)")
67
      // @RequestParam("UCSBOrganizationTime")
68
      // @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
69
      // ZonedDateTime UCSBOrganizationTime)
70
      throws JsonProcessingException {
71
72
    // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
73
    // See: https://www.baeldung.com/spring-date-parameters
74
75
    // log.info("UCSBOrganizationTime={}", UCSBOrganizationTime);
76
77
    UCSBOrganization ucsbOrganization = new UCSBOrganization();
78 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    ucsbOrganization.setOrgCode(orgCode);
79 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    ucsbOrganization.setOrgTranslation(orgTranslation);
80 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    ucsbOrganization.setOrgTranslationShort(orgTranslationShort);
81 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    ucsbOrganization.setInactive(inactive);
82
83
    UCSBOrganization savedUCSBOrganization = ucsbOrganizationRepository.save(ucsbOrganization);
84
85 1 1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postUCSBOrganization → KILLED
    return savedUCSBOrganization;
86
  }
87
88
  /**
89
   * Get a single UCSBOrganization by id
90
   *
91
   * @param id the id of the date
92
   * @return a UCSBOrganization
93
   */
94
  @Operation(summary = "Get a single UCSBOrganization")
95
  @PreAuthorize("hasRole('ROLE_USER')")
96
  @GetMapping("")
97
  public UCSBOrganization getById(@Parameter(name = "id") @RequestParam Long id) {
98
    UCSBOrganization ucsbOrganization =
99
        ucsbOrganizationRepository
100
            .findById(id)
101 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, id));
102
103 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return ucsbOrganization;
104
  }
105
106
  /**
107
   * Update a single ucsborganization
108
   *
109
   * @param id id of the ucsb organization to update
110
   * @param incoming the new ucsb organization
111
   * @return the updated ucsb organization object
112
   */
113
  @Operation(summary = "Update a single UCSBOrganization")
114
  @PreAuthorize("hasRole('ROLE_ADMIN')")
115
  @PutMapping("")
116
  public UCSBOrganization updateUCSBOrganization(
117
      @Parameter(name = "id") @RequestParam Long id,
118
      @RequestBody @Valid UCSBOrganization incoming) {
119
120
    UCSBOrganization ucsbOrganization =
121
        ucsbOrganizationRepository
122
            .findById(id)
123 1 1. lambda$updateUCSBOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateUCSBOrganization$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, id));
124
125 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    ucsbOrganization.setOrgCode(incoming.getOrgCode());
126 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    ucsbOrganization.setOrgTranslation(incoming.getOrgTranslation());
127 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    ucsbOrganization.setOrgTranslationShort(incoming.getOrgTranslationShort());
128 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    ucsbOrganization.setInactive(incoming.getInactive());
129
130
    ucsbOrganizationRepository.save(ucsbOrganization);
131
132 1 1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateUCSBOrganization → KILLED
    return ucsbOrganization;
133
  }
134
135
  /**
136
   * Delete a UCSBOrganization
137
   *
138
   * @param id the id of the UCSBOrganization to delete
139
   * @return a message indicating the UCSBOrganization was deleted
140
   */
141
  @Operation(summary = "Delete a UCSBOrganization")
142
  @PreAuthorize("hasRole('ROLE_ADMIN')")
143
  @DeleteMapping("")
144
  public Object deleteUCSBDate(@Parameter(name = "id") @RequestParam Long id) {
145
    UCSBOrganization ucsbOrganization =
146
        ucsbOrganizationRepository
147
            .findById(id)
148 1 1. lambda$deleteUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteUCSBDate$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, id));
149
150 1 1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(ucsbOrganization);
151 1 1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteUCSBDate → KILLED
    return genericMessage("UCSBOrganization with id %s deleted".formatted(id));
152
  }
153
}

Mutations

42

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

78

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_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED

79

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_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED

80

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_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

81

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_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED

85

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

101

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

103

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_does_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED

123

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

125

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_existing_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED

126

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_existing_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED

127

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_existing_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

128

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_existing_UCSBOrganization()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED

132

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_existing_UCSBOrganization()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateUCSBOrganization → KILLED

148

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

150

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

151

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

Active mutators

Tests examined


Report generated by PIT 1.17.0