Browse Source

to feature #7169 (#7170)

Co-authored-by: ouyangyewei <yewei.oyyw@alibaba-inc.com>
3.0.0/version-upgrade
ouyangyewei 3 years ago committed by GitHub
parent
commit
db090685a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  2. 12
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/enums/StatusTest.java

15
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.api.enums;
import java.util.Locale;
import java.util.Optional;
import org.springframework.context.i18n.LocaleContextHolder;
@ -382,4 +383,18 @@ public enum Status {
return this.enMsg;
}
}
/**
* Retrieve Status enum entity by status code.
* @param code
* @return
*/
public static Optional<Status> findStatusBy(int code) {
for (Status status : Status.values()) {
if (code == status.getCode()) {
return Optional.of(status);
}
}
return Optional.empty();
}
}

12
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/enums/StatusTest.java

@ -21,6 +21,7 @@ import org.junit.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.Locale;
import java.util.Optional;
import static org.junit.Assert.*;
@ -41,4 +42,15 @@ public class StatusTest {
Assert.assertEquals("成功", Status.SUCCESS.getMsg());
}
@Test
public void testGetStatusByCode() {
// FAILURE
Optional<Status> optional = Status.findStatusBy(1);
Assert.assertFalse(optional.isPresent());
// SUCCESS
optional = Status.findStatusBy(10018);
Assert.assertTrue(optional.isPresent());
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, optional.get());
}
}

Loading…
Cancel
Save