UCSBOrganizationsController.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 UCSBOrganizations */
23
@Tag(name = "UCSBOrganizations")
24
@RequestMapping("/api/ucsborganizations")
25
@RestController
26
@Slf4j
27
public class UCSBOrganizationsController 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 ucsb 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/UCSBOrganizationsController::allUCSBOrganizations → KILLED
    return organizations;
42
  }
43
44
  /**
45
   * Create a new date
46
   *
47
   * @param orgCode the organization code
48
   * @param orgTranslationShort the translation of code shortened
49
   * @param orgTranslation the translation of code
50
   * @param inactive whether the organization is inactive
51
   * @return the saved ucsborganization
52
   */
53
  @Operation(summary = "Create a new organization")
54
  @PreAuthorize("hasRole('ROLE_ADMIN')")
55
  @PostMapping("/post")
56
  public UCSBOrganization postUCSBOrganization(
57
      @Parameter(name = "orgCode") @RequestParam String orgCode,
58
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
59
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
60
      @Parameter(name = "inactive") @RequestParam Boolean inactive) {
61
62
    UCSBOrganization ucsbOrganization = new UCSBOrganization();
63 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    ucsbOrganization.setOrgCode(orgCode);
64 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    ucsbOrganization.setOrgTranslationShort(orgTranslationShort);
65 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    ucsbOrganization.setOrgTranslation(orgTranslation);
66 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    ucsbOrganization.setInactive(inactive);
67
68
    UCSBOrganization savedUcsbOrganization = ucsbOrganizationRepository.save(ucsbOrganization);
69
70 1 1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postUCSBOrganization → KILLED
    return savedUcsbOrganization;
71
  }
72
73
  /**
74
   * This method returns a single organization.
75
   *
76
   * @param orgCode code of the organization
77
   * @return a single organization
78
   */
79
  @Operation(summary = "Get a single organization")
80
  @PreAuthorize("hasRole('ROLE_USER')")
81
  @GetMapping("")
82
  public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) {
83
    UCSBOrganization organizations =
84
        ucsbOrganizationRepository
85
            .findById(orgCode)
86 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
87
88 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getById → KILLED
    return organizations;
89
  }
90
91
  /**
92
   * Update a single organization. Accessible only to users with the role "ROLE_ADMIN".
93
   *
94
   * @param orgCode code of the organization
95
   * @param incoming the new organizations contents
96
   * @return the updated commons object
97
   */
98
  @Operation(summary = "Update a single organization")
99
  @PreAuthorize("hasRole('ROLE_ADMIN')")
100
  @PutMapping("")
101
  public UCSBOrganization updateOrganization(
102
      @Parameter(name = "orgCode") @RequestParam String orgCode,
103
      @RequestBody @Valid UCSBOrganization incoming) {
104
105
    UCSBOrganization organizations =
106
        ucsbOrganizationRepository
107
            .findById(orgCode)
108 1 1. lambda$updateOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateOrganization$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
109
110 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    organizations.setOrgTranslation(incoming.getOrgTranslation());
111 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    organizations.setOrgTranslationShort(incoming.getOrgTranslationShort());
112 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    organizations.setInactive(incoming.getInactive());
113
114
    ucsbOrganizationRepository.save(organizations);
115
116 1 1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateOrganization → KILLED
    return organizations;
117
  }
118
119
  /**
120
   * Delete an organization. Accessible only to users with the role "ROLE_ADMIN".
121
   *
122
   * @param orgCode code of the organization
123
   * @return a message indiciating the organization was deleted
124
   */
125
  @Operation(summary = "Delete a UCSBOrganization")
126
  @PreAuthorize("hasRole('ROLE_ADMIN')")
127
  @DeleteMapping("")
128
  public Object deleteOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) {
129
    UCSBOrganization organizations =
130
        ucsbOrganizationRepository
131
            .findById(orgCode)
132 1 1. lambda$deleteOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteOrganization$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
133
134 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(organizations);
135 1 1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteOrganization → KILLED
    return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode));
136
  }
137
}

Mutations

41

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

63

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

64

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

65

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

66

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

70

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

86

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[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/UCSBOrganizationsController::lambda$getById$0 → KILLED

88

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[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/UCSBOrganizationsController::getById → KILLED

108

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

110

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

111

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

112

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

116

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

132

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

134

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

135

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

Active mutators

Tests examined


Report generated by PIT 1.17.0