@@ -141,27 +141,25 @@ public List<Flow> listByCredential(String secretName) {
141141
142142 @ Override
143143 public Boolean exist (String name ) {
144- try {
145- Flow flow = get (name );
146- return flow .getStatus () != Status .PENDING ;
147- } catch (NotFoundException e ) {
144+ Optional <Flow > optional = flowDao .findByName (name );
145+ if (optional .isEmpty ()) {
148146 return false ;
149147 }
148+ return optional .get ().getStatus () == Status .CONFIRMED ;
150149 }
151150
152151 @ Override
153152 public Flow create (String name ) {
154153 Flow .validateName (name );
155154 String email = sessionManager .getUserEmail ();
156155
157- Flow flow = flowDao .findByName (name );
158- if (flow != null && flow .getStatus () == Status .CONFIRMED ) {
156+ if (exist (name )) {
159157 throw new DuplicateException ("Flow {0} already exists" , name );
160158 }
161159
162160 // reuse from pending list
163161 List <Flow > pending = flowDao .findAllByStatusAndCreatedBy (Status .PENDING , email );
164- flow = pending .size () > 0 ? pending .get (0 ) : new Flow ();
162+ var flow = pending .size () > 0 ? pending .get (0 ) : new Flow ();
165163
166164 // set properties
167165 flow .setName (name );
@@ -231,11 +229,12 @@ public Flow confirm(String name, ConfirmOption option) {
231229
232230 @ Override
233231 public Flow get (String name ) {
234- Flow flow = flowDao .findByName (name );
235- if (Objects .isNull (flow )) {
232+ Optional <Flow > optional = flowDao .findByName (name );
233+
234+ if (optional .isEmpty ()) {
236235 throw new NotFoundException ("Flow {0} is not found" , name );
237236 }
238- return flow ;
237+ return optional . get () ;
239238 }
240239
241240 @ Override
@@ -322,8 +321,13 @@ public void deleteUserFromFlow(UserDeletedEvent event) {
322321 @ EventListener
323322 public void onGitHookEvent (GitHookEvent event ) {
324323 GitTrigger trigger = event .getTrigger ();
325- Flow flow = flowDao .findByName (event .getFlow ());
324+ Optional <Flow > optional = flowDao .findByName (event .getFlow ());
325+ if (optional .isEmpty ()) {
326+ log .warn ("The flow {} doesn't exist" , event .getFlow ());
327+ return ;
328+ }
326329
330+ var flow = optional .get ();
327331 if (event .isPingEvent ()) {
328332 GitPingTrigger ping = (GitPingTrigger ) trigger ;
329333
0 commit comments