/
BeginPushController.java
89 lines (77 loc) · 3.51 KB
/
BeginPushController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright (c) 2017 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Erik Merkle (Boundless) - initial implementation
*/
package org.locationtech.geogig.spring.controller;
import static org.locationtech.geogig.rest.repository.RepositoryProvider.BASE_REPOSITORY_ROUTE;
import static org.locationtech.geogig.rest.repository.RepositoryProvider.GEOGIG_ROUTE_PREFIX;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS;
import static org.springframework.web.bind.annotation.RequestMethod.PATCH;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
import static org.springframework.web.bind.annotation.RequestMethod.TRACE;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.locationtech.geogig.rest.repository.RepositoryProvider;
import org.locationtech.geogig.spring.dto.PushResponse;
import org.locationtech.geogig.spring.service.LegacyPushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Sets;
/**
*
*/
@RestController
@RequestMapping(path = GEOGIG_ROUTE_PREFIX + "/" + BASE_REPOSITORY_ROUTE
+ "/{repoName}/repo/beginpush")
public class BeginPushController extends AbstractRepositoryController {
private static final Logger LOGGER = LoggerFactory.getLogger(BeginPushController.class);
@Autowired
private LegacyPushService legacyPushService;
@RequestMapping(method = {PUT, POST, DELETE, PATCH, TRACE, OPTIONS})
public void catchAll() {
// if we hit this controller, it's a 405
supportedMethods(Sets.newHashSet(GET.toString()));
}
@GetMapping
public void getBeginPush(@PathVariable(name = "repoName") String repoName,
@RequestParam(name = "internalIp", required = false) String internalIp,
HttpServletRequest request, HttpServletResponse response) {
// get the provider
Optional<RepositoryProvider> optional = getRepoProvider(request);
if (optional.isPresent()) {
final RepositoryProvider provider = optional.get();
// ensure the repo exists and is opened
if (!isOpenRepository(provider, repoName, response)) {
// done
return;
}
// get the client IP
final String clientIp = request.getRemoteAddr();
// make service call
PushResponse beginPush = legacyPushService.beginPush(clientIp, internalIp);
// encode response
encode(beginPush, request, response);
} else {
throw NO_PROVIDER;
}
}
@Override
protected Logger getLogger() {
return LOGGER;
}
}