5
5
6
6
package org .geoserver .geofence .services .rest .impl ;
7
7
8
+ import java .util .HashMap ;
8
9
import java .util .HashSet ;
9
10
import java .util .List ;
11
+ import java .util .Map ;
10
12
import java .util .Set ;
11
13
import javax .ws .rs .core .Response ;
12
14
import javax .ws .rs .core .Response .Status ;
13
15
14
16
15
17
import org .apache .commons .lang .StringUtils ;
16
18
19
+ import org .geoserver .geofence .core .model .RuleLimits ;
20
+ import org .geoserver .geofence .services .rest .model .RESTRuleLimits ;
17
21
import org .locationtech .jts .geom .Geometry ;
18
22
import org .locationtech .jts .geom .MultiPolygon ;
19
23
import org .locationtech .jts .io .ParseException ;
55
59
import java .util .Arrays ;
56
60
import java .util .ArrayList ;
57
61
import java .util .Comparator ;
62
+ import java .util .stream .Collectors ;
58
63
59
64
/**
60
65
*
@@ -88,7 +93,6 @@ public RESTOutputRule get(Long id) throws BadRequestRestEx, NotFoundRestEx, Inte
88
93
}
89
94
90
95
@ Override
91
- @ Transactional (propagation = Propagation .REQUIRED , value = "geofenceTransactionManager" )
92
96
public Response insert (RESTInputRule inputRule ) throws NotFoundRestEx , BadRequestRestEx , InternalErrorRestEx {
93
97
94
98
if (inputRule .getPosition () == null || inputRule .getPosition ().getPosition () == null ) {
@@ -115,6 +119,11 @@ public Response insert(RESTInputRule inputRule) throws NotFoundRestEx, BadReques
115
119
ruleAdminService .setDetails (id , details );
116
120
}
117
121
122
+ RuleLimits limits =limitsFromInput (inputRule .getLimits ());
123
+ if (limits !=null ) {
124
+ ruleAdminService .setLimits (id ,limits );
125
+ }
126
+
118
127
return Response .status (Status .CREATED ).tag (id .toString ()).entity (id ).build ();
119
128
} catch (BadRequestServiceEx ex ) {
120
129
LOGGER .error (ex .getMessage ());
@@ -125,6 +134,13 @@ public Response insert(RESTInputRule inputRule) throws NotFoundRestEx, BadReques
125
134
}
126
135
}
127
136
137
+ private InsertPosition insertPosition (RESTInputRule inputRule ){
138
+ return
139
+ inputRule .getPosition ().getPosition () == RulePosition .fixedPriority ? InsertPosition .FIXED
140
+ : inputRule .getPosition ().getPosition () == RulePosition .offsetFromBottom ? InsertPosition .FROM_END
141
+ : inputRule .getPosition ().getPosition () == RulePosition .offsetFromTop ? InsertPosition .FROM_START : null ;
142
+ }
143
+
128
144
@ Override
129
145
public void update (Long id , RESTInputRule rule ) throws BadRequestRestEx , NotFoundRestEx , InternalErrorRestEx {
130
146
@@ -579,6 +595,25 @@ protected RESTOutputRule toOutput(Rule rule) {
579
595
out .setConstraints (constraints );
580
596
}
581
597
598
+ if (rule .getRuleLimits ()!=null ){
599
+ RESTRuleLimits ruleLimits =new RESTRuleLimits ();
600
+ RuleLimits limits =rule .getRuleLimits ();
601
+ if (limits .getSpatialFilterType ()!=null )
602
+ ruleLimits .setSpatialFilterType (limits .getSpatialFilterType ());
603
+ if (limits .getCatalogMode ()!=null )
604
+ ruleLimits .setCatalogMode (limits .getCatalogMode ());
605
+ if (limits .getAllowedArea ()!=null ) {
606
+ MultiPolygon area = limits .getAllowedArea ();
607
+ if (area != null ) {
608
+ String areaWKT = "SRID=" + area .getSRID () + ";" + area .toText ();
609
+ ruleLimits .setRestrictedAreaWkt (areaWKT );
610
+ }
611
+ if (limits .getSpatialFilterType ()!=null )
612
+ ruleLimits .setSpatialFilterType (limits .getSpatialFilterType ());
613
+ }
614
+ out .setLimits (ruleLimits );
615
+ }
616
+
582
617
return out ;
583
618
}
584
619
@@ -608,6 +643,28 @@ protected Rule fromInput(RESTInputRule in) {
608
643
return rule ;
609
644
}
610
645
646
+ protected RuleLimits limitsFromInput (RESTRuleLimits in ){
647
+ RuleLimits limits =null ;
648
+ if (in !=null && (in .getCatalogMode ()!=null || in .getRestrictedAreaWkt ()!=null )){
649
+ limits =new RuleLimits ();
650
+ limits .setCatalogMode (in .getCatalogMode ());
651
+ limits .setSpatialFilterType (in .getSpatialFilterType ());
652
+ if (StringUtils .isNotBlank (in .getRestrictedAreaWkt ())) {
653
+ if (in .getRestrictedAreaWkt () != null ) {
654
+ Geometry g ;
655
+ try {
656
+ g = toGeometryAllowedArea (in .getRestrictedAreaWkt ());
657
+ } catch (ParseException ex ) {
658
+ throw new BadRequestRestEx ("Error parsing WKT:" + ex .getMessage ());
659
+ }
660
+ limits .setAllowedArea ((MultiPolygon ) g );
661
+ }
662
+ }
663
+ }
664
+ return limits ;
665
+ }
666
+
667
+
611
668
protected LayerDetails detailsFromInput (RESTInputRule in ) {
612
669
RESTLayerConstraints constraints = in .getConstraints ();
613
670
if (constraints != null ) {
0 commit comments