File tree Expand file tree Collapse file tree
main/java/org/apache/dolphinscheduler/api/enums
test/java/org/apache/dolphinscheduler/api/enums Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818package org .apache .dolphinscheduler .api .enums ;
1919
2020import java .util .Locale ;
21+ import java .util .Optional ;
2122
2223import org .springframework .context .i18n .LocaleContextHolder ;
2324
@@ -382,4 +383,18 @@ public String getMsg() {
382383 return this .enMsg ;
383384 }
384385 }
386+
387+ /**
388+ * Retrieve Status enum entity by status code.
389+ * @param code
390+ * @return
391+ */
392+ public static Optional <Status > findStatusBy (int code ) {
393+ for (Status status : Status .values ()) {
394+ if (code == status .getCode ()) {
395+ return Optional .of (status );
396+ }
397+ }
398+ return Optional .empty ();
399+ }
385400}
Original file line number Diff line number Diff line change 2121import org .springframework .context .i18n .LocaleContextHolder ;
2222
2323import java .util .Locale ;
24+ import java .util .Optional ;
2425
2526import static org .junit .Assert .*;
2627
@@ -41,4 +42,15 @@ public void testGetMsg() {
4142 Assert .assertEquals ("成功" , Status .SUCCESS .getMsg ());
4243 }
4344
45+ @ Test
46+ public void testGetStatusByCode () {
47+ // FAILURE
48+ Optional <Status > optional = Status .findStatusBy (1 );
49+ Assert .assertFalse (optional .isPresent ());
50+
51+ // SUCCESS
52+ optional = Status .findStatusBy (10018 );
53+ Assert .assertTrue (optional .isPresent ());
54+ Assert .assertEquals (Status .PROJECT_NOT_FOUNT , optional .get ());
55+ }
4456}
You can’t perform that action at this time.
0 commit comments