getOne(JwtAuthenticationToken,String)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
rs 10
eloc 5
1
/**
2
 * 
3
 */
4
package unicon.matthews.oneroster.endpoint;
5
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.http.HttpHeaders;
8
import org.springframework.http.HttpStatus;
9
import org.springframework.http.ResponseEntity;
10
import org.springframework.web.bind.annotation.PathVariable;
11
import org.springframework.web.bind.annotation.RequestBody;
12
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RequestMethod;
14
import org.springframework.web.bind.annotation.RestController;
15
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
16
17
import unicon.matthews.entity.DataSync;
18
import unicon.matthews.oneroster.Org;
19
import unicon.matthews.oneroster.exception.OrgNotFoundException;
20
import unicon.matthews.oneroster.service.OrgService;
21
import unicon.matthews.security.auth.JwtAuthenticationToken;
22
import unicon.matthews.security.model.UserContext;
23
24
/**
25
 * @author ggilbert
26
 *
27
 */
28
@RestController
29
@RequestMapping("/api/orgs")
30
public class OrgController {
31
  
32
  private OrgService orgService;
33
  
34
  @Autowired
35
  public OrgController(OrgService orgService) {
36
    this.orgService = orgService;
37
  }
38
39
  @RequestMapping(method = RequestMethod.POST)
40
  public ResponseEntity<?> post(JwtAuthenticationToken token, @RequestBody Org org) {
0 ignored issues
show
Comprehensibility introduced by
Remove usage of generic wildcard type.
Loading history...
41
    UserContext userContext = (UserContext) token.getPrincipal();
42
    Org savedOrg = this.orgService.save(userContext.getTenantId(), org);
43
    HttpHeaders httpHeaders = new HttpHeaders();
44
    httpHeaders.setLocation(ServletUriComponentsBuilder
45
        .fromCurrentRequest().path("/{id}")
46
        .buildAndExpand(savedOrg.getSourcedId()).toUri());
47
    return new ResponseEntity<>(savedOrg, httpHeaders, HttpStatus.CREATED);
48
  }
49
50
  @RequestMapping(value = "/{orgId}", method = RequestMethod.GET)
51
  public Org getOne(JwtAuthenticationToken token, @PathVariable final String orgId) throws OrgNotFoundException {
52
    UserContext userContext = (UserContext) token.getPrincipal();
53
    Org maybeOrg = this.orgService.findByTenantIdAndOrgSourcedId(userContext.getTenantId(), orgId);
54
    return maybeOrg;
55
  }
56
  
57
  @RequestMapping(value = "/{orgId}/datasyncs/{syncType}", method = RequestMethod.GET)
58
  public DataSync getLatestDataSync(JwtAuthenticationToken token, @PathVariable final String orgId, @PathVariable final String syncType) {
59
    UserContext userContext = (UserContext) token.getPrincipal();
60
    return this.orgService.findLatestDataSync(userContext.getTenantId(), orgId, syncType);
61
  }
62
  
63
  @RequestMapping(value = "/{orgId}/datasyncs", method = RequestMethod.POST)
64
  public ResponseEntity<?> postDataSync(JwtAuthenticationToken token, @PathVariable final String orgId, @RequestBody DataSync dataSync) {
0 ignored issues
show
Comprehensibility introduced by
Remove usage of generic wildcard type.
Loading history...
65
    UserContext userContext = (UserContext) token.getPrincipal();
66
    this.orgService.saveDataSync(userContext.getTenantId(), orgId, dataSync);
67
    return new ResponseEntity<>(HttpStatus.OK);
68
  }
69
70
}
71