4949import com .here .xyz .hub .auth .Authorization ;
5050import com .here .xyz .hub .auth .FeatureAuthorization ;
5151import com .here .xyz .hub .config .BranchConfigClient ;
52+ import com .here .xyz .hub .config .TagConfigClient ;
5253import com .here .xyz .hub .connectors .RpcClient ;
5354import com .here .xyz .hub .connectors .models .Connector ;
5455import com .here .xyz .hub .connectors .models .Space ;
@@ -147,13 +148,25 @@ private FeatureTask(T event, RoutingContext context, ApiResponseType responseTyp
147148 this .requestBodySize = requestBodySize ;
148149 }
149150
150- //TODO: Merge into resolveVersionRef
151- void resolveBranch (final X task , final Callback <X > callback ) {
151+ void resolveVersionRef (final X task , final Callback <X > callback ) {
152152 try {
153153 if (task .getEvent () instanceof ContextAwareEvent <?> event ) {
154- resolveBranchFor (event , task .space )
155- .onFailure (callback ::exception )
156- .onSuccess (v -> callback .call (task ));
154+ Future <Void > future = Future .succeededFuture ();
155+ if (event .getRef ().isTag ()) {
156+ future = TagConfigClient .getInstance ().getTag (task .getMarker (), event .getRef ().getTag (), task .space .getId ())
157+ .compose (tag -> {
158+ if (tag == null ) {
159+ //It could be a branch
160+ event .setRef (Ref .fromBranchId (event .getRef ().getTag ()));
161+ } else {
162+ event .setRef (tag .getVersionRef ());
163+ }
164+ return Future .succeededFuture ();
165+ });
166+ }
167+ future .compose (v -> resolveBranchFor (event , task .space ))
168+ .onFailure (callback ::exception )
169+ .onSuccess (v -> callback .call (task ));
157170 } else
158171 callback .call (task );
159172 } catch (Exception e ) {
@@ -162,27 +175,11 @@ void resolveBranch(final X task, final Callback<X> callback) {
162175 }
163176
164177 public static Future <Void > resolveBranchFor (ContextAwareEvent <?> event , Space space ) {
165- if (event .getRef () == null || ( event .getRef ().isMainBranch () && ! event . getRef (). isTag () ))
178+ if (event .getRef () == null || event .getRef ().isMainBranch ())
166179 return Future .succeededFuture ();
167180
168- Ref branchRef = event .getRef ().isTag () ? Ref .fromBranchId (event .getRef ().getTag ()) : event .getRef ();
169- Future <Branch > future = getReferencedBranch (space .getId (), branchRef );
170- if (event .getRef ().isTag ()) {
171- // Check if it's a branch or a tag
172- future = future .compose (branch -> {
173- if (branch != null )
174- event .setRef (branchRef );
175- return Future .succeededFuture (branch );
176- })
177- .recover (t -> {
178- // If the branch does not exist, then it could be a normal tag
179- if (t instanceof HttpException e && e .status == NOT_FOUND )
180- return Future .succeededFuture ();
181- return Future .failedFuture (t );
182- });
183- }
184-
185- return future .compose (referencedBranch -> {
181+ return getReferencedBranch (space .getId (), event .getRef ())
182+ .compose (referencedBranch -> {
186183 if (referencedBranch != null ) {
187184 LinkedList <Ref > branchPath = new LinkedList <>(referencedBranch .getBranchPath ());
188185 event .withNodeId (referencedBranch .getNodeId ())
@@ -211,7 +208,7 @@ public static Future<Branch> getReferencedBranch(String spaceId, Ref ref) {
211208 return BranchConfigClient .getInstance ().load (spaceId , ref .getBranch ())
212209 .compose (branch -> {
213210 if (branch == null )
214- return Future .failedFuture (new HttpException (NOT_FOUND , "Branch \" " + ref .getBranch () + "\" was not found on resource \" " + spaceId + "\" ." ));
211+ return Future .failedFuture (new HttpException (NOT_FOUND , "Tag or Branch \" " + ref .getBranch () + "\" was not found on resource \" " + spaceId + "\" ." ));
215212 return Future .succeededFuture (branch );
216213 });
217214 }
@@ -342,8 +339,7 @@ public GeometryQuery(GetFeaturesByGeometryEvent event, RoutingContext context, A
342339 public TaskPipeline <GeometryQuery > createPipeline () {
343340 return TaskPipeline .create (this )
344341 .then (FeatureTaskHandler ::resolveSpace )
345- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef and move back again after checkImmutability
346- .then (FeatureTaskHandler ::resolveVersionRef )
342+ .then (this ::resolveVersionRef )
347343 .then (this ::resolveRefSpace )
348344 .then (this ::resolveRefConnector )
349345 .then (Authorization ::authorizeComposite )
@@ -473,8 +469,7 @@ public BBoxQuery(GetFeaturesByBBoxEvent event, RoutingContext context, ApiRespon
473469 public TaskPipeline <BBoxQuery > createPipeline () {
474470 return TaskPipeline .create (this )
475471 .then (FeatureTaskHandler ::resolveSpace )
476- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef and move back again after checkImmutability
477- .then (FeatureTaskHandler ::resolveVersionRef )
472+ .then (this ::resolveVersionRef )
478473 .then (Authorization ::authorizeComposite )
479474 .then (FeatureAuthorization ::authorize )
480475 .then (FeatureTaskHandler ::checkImmutability )
@@ -504,8 +499,7 @@ public TileQuery(GetFeaturesByTileEvent event, RoutingContext context, ApiRespon
504499 public TaskPipeline <TileQuery > createPipeline () {
505500 return TaskPipeline .create (this )
506501 .then (FeatureTaskHandler ::resolveSpace )
507- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef and move back again after checkImmutability
508- .then (FeatureTaskHandler ::resolveVersionRef )
502+ .then (this ::resolveVersionRef )
509503 .then (Authorization ::authorizeComposite )
510504 .then (FeatureAuthorization ::authorize )
511505 .then (FeatureTaskHandler ::checkImmutability )
@@ -540,8 +534,7 @@ public IdsQuery(GetFeaturesByIdEvent event, RoutingContext context, ApiResponseT
540534 public TaskPipeline <IdsQuery > createPipeline () {
541535 return TaskPipeline .create (this )
542536 .then (FeatureTaskHandler ::resolveSpace )
543- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef and move back again after auth
544- .then (FeatureTaskHandler ::resolveVersionRef )
537+ .then (this ::resolveVersionRef )
545538 .then (Authorization ::authorizeComposite )
546539 .then (FeatureAuthorization ::authorize )
547540 .then (FeatureTaskHandler ::checkImmutability )
@@ -562,8 +555,7 @@ public IterateQuery(IterateFeaturesEvent event, RoutingContext context, ApiRespo
562555 public TaskPipeline <IterateQuery > createPipeline () {
563556 return TaskPipeline .create (this )
564557 .then (FeatureTaskHandler ::resolveSpace )
565- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef and move back again after auth
566- .then (FeatureTaskHandler ::resolveVersionRef )
558+ .then (this ::resolveVersionRef )
567559 .then (Authorization ::authorizeComposite )
568560 .then (FeatureAuthorization ::authorize )
569561 .then (FeatureTaskHandler ::checkImmutability )
@@ -584,8 +576,7 @@ public SearchQuery(SearchForFeaturesEvent<?> event, RoutingContext context, ApiR
584576 public TaskPipeline <SearchQuery > createPipeline () {
585577 return TaskPipeline .create (this )
586578 .then (FeatureTaskHandler ::resolveSpace )
587- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef and move back again after auth
588- .then (FeatureTaskHandler ::resolveVersionRef )
579+ .then (this ::resolveVersionRef )
589580 .then (Authorization ::authorizeComposite )
590581 .then (FeatureAuthorization ::authorize )
591582 .then (FeatureTaskHandler ::checkImmutability )
@@ -610,7 +601,7 @@ public TaskPipeline<GetStatistics> createPipeline() {
610601 .then (FeatureTaskHandler ::resolveSpace )
611602 .then (Authorization ::authorizeComposite )
612603 .then (FeatureAuthorization ::authorize )
613- .then (this ::resolveBranch ) //TODO: Merge into resolveVersionRef?
604+ .then (this ::resolveVersionRef )
614605 .then (FeatureTaskHandler ::readCache )
615606 .then (FeatureTaskHandler ::invoke )
616607 .then (FeatureTaskHandler ::convertResponse )
@@ -639,7 +630,7 @@ public void onPreProcessed(ModifySpaceEvent event) {
639630 public TaskPipeline <ModifySpaceQuery > createPipeline () {
640631 return TaskPipeline .create (this )
641632 .then (FeatureTaskHandler ::resolveSpace )
642- .then (this ::resolveBranch )
633+ .then (this ::resolveVersionRef )
643634 .then (SpaceTaskHandler ::invokeConditionally );
644635 }
645636 }
@@ -699,7 +690,7 @@ public TaskPipeline<ConditionalOperation> createPipeline() {
699690 .then (FeatureTaskHandler ::resolveSpace )
700691 .then (FeatureTaskHandler ::registerRequestMemory )
701692 .then (FeatureTaskHandler ::throttle )
702- .then (this ::resolveBranch )
693+ .then (this ::resolveVersionRef )
703694 .then (FeatureTaskHandler ::injectSpaceParams )
704695 .then (FeatureTaskHandler ::checkPreconditions )
705696 .then (FeatureTaskHandler ::prepareModifyFeatureOp )
0 commit comments