Skip to content

Commit

Permalink
GEOS-8239 Support Limits and LayerDetails in geofence internal server…
Browse files Browse the repository at this point in the history
… REST
  • Loading branch information
NielsCharlier committed Aug 28, 2017
1 parent e2d905b commit 00c38cf
Show file tree
Hide file tree
Showing 7 changed files with 590 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/community/geofence-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.geotools.xsd</groupId>
<artifactId>gt-xsd-gml3</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
<version>${gt.version}</version>
</dependency>

<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.geoserver.geofence.services.dto.RuleFilter.SpecialFilterType;
import org.geoserver.geofence.services.dto.RuleFilter.TextFilter;
import org.geoserver.geofence.services.dto.ShortRule;
import org.geoserver.geofence.services.exception.BadRequestServiceEx;
import org.geoserver.geofence.services.exception.NotFoundServiceEx;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -53,6 +55,16 @@ public void ruleNotFound(NotFoundServiceEx exception, HttpServletRequest request
public void rule(DuplicateKeyException exception, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendError(409, exception.getMessage());
}

@ExceptionHandler(BadRequestServiceEx.class)
public void badRequest(BadRequestServiceEx exception, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendError(400, exception.getMessage());
}

@ExceptionHandler(HttpMessageNotReadableException.class)
public void messageNotReadableException(HttpMessageNotReadableException exception, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendError(400, exception.getMessage());
}

@RequestMapping(value = "/rest/rules", method = RequestMethod.GET, produces={"application/xml", "application/json"})
public @ResponseBody JaxbRuleList get(
Expand Down Expand Up @@ -131,8 +143,16 @@ public ResponseEntity<Long> insert(@RequestBody JaxbRule rule) {
adminService.shift(priority, 1);
}

return new ResponseEntity<Long>(adminService.insert(rule.toRule()),
HttpStatus.CREATED);
Long id = adminService.insert(rule.toRule());

if (rule.getLimits() != null) {
adminService.setLimits(id, rule.getLimits().toRuleLimits(null));
}
if (rule.getLayerDetails() != null) {
adminService.setDetails(id, rule.getLayerDetails().toLayerDetails(null));
}

return new ResponseEntity<Long>(id, HttpStatus.CREATED);
}

@RequestMapping(value = "/rest/rules/id/{id}", method = RequestMethod.POST)
Expand All @@ -143,9 +163,40 @@ public ResponseEntity<Long> insert(@RequestBody JaxbRule rule) {
adminService.shift(rule.getPriority().longValue(), 1);
}
}
adminService.update(rule.toRule(adminService.get(id)));
Rule theRule = adminService.get(id);
adminService.update(rule.toRule(theRule));
if (rule.getLimits() != null) {
adminService.setLimits(id, rule.getLimits().toRuleLimits(theRule.getRuleLimits()));
}
if (rule.getLayerDetails() != null) {
adminService.setDetails(id, rule.getLayerDetails().toLayerDetails(theRule.getLayerDetails()));
}
}

@RequestMapping(value = "/rest/rules/id/{id}", method = RequestMethod.PUT)
public @ResponseStatus(HttpStatus.OK) void clearAndUpdate(@PathVariable ("id") Long id, @RequestBody JaxbRule rule) {
if (rule.getPriority() != null) {
ShortRule priorityRule = adminService.getRuleByPriority(rule.getPriority().longValue());
if (priorityRule != null && priorityRule.getId() != id) {
adminService.shift(rule.getPriority().longValue(), 1);
}
}
Rule theRule = new Rule();
theRule.setId(id);
adminService.update(rule.toRule(theRule));
if (rule.getLimits() != null) {
adminService.setLimits(id, rule.getLimits().toRuleLimits(null));
} else {
adminService.setLimits(id, null);
}
if (rule.getLayerDetails() != null) {
adminService.setDetails(id, rule.getLayerDetails().toLayerDetails(null));
} else {
adminService.setDetails(id, null);
}
}


@RequestMapping(value = "/rest/rules/id/{id}", method = RequestMethod.DELETE)
public @ResponseStatus(HttpStatus.OK) void delete(@PathVariable("id") Long id) {
adminService.delete(id);
Expand Down Expand Up @@ -266,5 +317,7 @@ private List<Rule> findRules(String rulesIds) {

@ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Invalid rules ids")
private class InvalidRulesIds extends RuntimeException {

private static final long serialVersionUID = -5682676569555830473L;
}
}

0 comments on commit 00c38cf

Please sign in to comment.