Created
December 1, 2017 18:13
-
-
Save sergii4/ad6511d0688c75ff8731fdb83812b0ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//what i suggest | |
@Command(name = "list-assets", description = "List all defined assets. Usage: `list-assets <ID>`") | |
public String listAssets(@Param(name = "id", description = "Model ID") String id) { | |
return Try.of(() -> simplAPI.listAssets(id)) | |
.recover(x -> Match(x).of( | |
Case($(instanceOf(ValidationException.class)), | |
t -> getValidationErrorRunningCommandMessage("list-assets", "", t)), //move logging to the SIMPL methods itself | |
Case($(instanceOf(Exception.class)), | |
t -> getErrorRunningCommandMessage("list-assets", t)) //move logging to the SIMPL methods itself | |
)) | |
.get(); | |
} | |
/*why should we consider this approach | |
- our code goes funtional nad it makes it more reusable | |
- increase the expressiveness of the code | |
- Efficient write operations are added by sharing immutable memory between instances. What we get is thread-safety for free! (see http://www.vavr.io/vavr-docs/#_values) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//how we handle command exception now | |
@Command(name = "list-scenarios", description = "List all defined scenarios. Usage: `list-scenarios <ID>`") | |
public String listScenarios(@Param(name = "id", description = "Model ID") String id) { | |
String scenarios = null; | |
try { | |
scenarios = simplAPI.listScenarios(id); | |
} catch (ValidationException e) { | |
LOGGER.error("Error while running command", e); | |
return getValidationErrorRunningCommandMessage("list-scenarios", "", e); | |
} catch (Exception e) { | |
LOGGER.error("Error while running command", e); | |
return getErrorRunningCommandMessage("list-scenarios", e); | |
} | |
return scenarios; | |
} | |
//it doesn't look really readable to me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment