@Test public void testPerformCancelAll() { JsonValue argValue = JsonValue.wrap(CancelSchedulesAction.ALL); ActionArguments args = createArgs(Action.SITUATION_MANUAL_INVOCATION, argValue); action.perform(args); verify(automation).cancelSchedules(Schedule.TYPE_ACTION); }
@NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { InAppAutomation automation; try { automation = actionAutomationCallable.call(); } catch (Exception e) { return ActionResult.newErrorResult(e); } JsonValue jsonValue = arguments.getValue().toJsonValue(); if (jsonValue.isString() && ALL.equalsIgnoreCase(jsonValue.getString())) { automation.cancelSchedules(Schedule.TYPE_ACTION); return ActionResult.newEmptyResult(); } JsonValue groupsJson = jsonValue.optMap().opt(GROUPS); if (groupsJson.isString()) { automation.cancelScheduleGroup(groupsJson.optString()); } else if (groupsJson.isJsonList()) { for (JsonValue value : groupsJson.optList()) { if (value.isString()) { automation.cancelScheduleGroup(value.optString()); } } } JsonValue idsJson = jsonValue.optMap().opt(IDS); if (idsJson.isString()) { automation.cancelSchedule(idsJson.optString()); } else if (idsJson.isJsonList()) { for (JsonValue value : idsJson.optList()) { if (value.isString()) { automation.cancelSchedule(value.optString()); } } } return ActionResult.newEmptyResult(); }
CancelSchedulesAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { InAppAutomation automation; try { automation = actionAutomationCallable.call(); } catch (Exception e) { return ActionResult.newErrorResult(e); } JsonValue jsonValue = arguments.getValue().toJsonValue(); if (jsonValue.isString() && ALL.equalsIgnoreCase(jsonValue.getString())) { automation.cancelSchedules(Schedule.TYPE_ACTION); return ActionResult.newEmptyResult(); } JsonValue groupsJson = jsonValue.optMap().opt(GROUPS); if (groupsJson.isString()) { automation.cancelScheduleGroup(groupsJson.optString()); } else if (groupsJson.isJsonList()) { for (JsonValue value : groupsJson.optList()) { if (value.isString()) { automation.cancelScheduleGroup(value.optString()); } } } JsonValue idsJson = jsonValue.optMap().opt(IDS); if (idsJson.isString()) { automation.cancelSchedule(idsJson.optString()); } else if (idsJson.isJsonList()) { for (JsonValue value : idsJson.optList()) { if (value.isString()) { automation.cancelSchedule(value.optString()); } } } return ActionResult.newEmptyResult(); } }
CancelSchedulesAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { InAppAutomation automation; try { automation = actionAutomationCallable.call(); } catch (Exception e) { return ActionResult.newErrorResult(e); } JsonValue jsonValue = arguments.getValue().toJsonValue(); if (jsonValue.isString() && ALL.equalsIgnoreCase(jsonValue.getString())) { automation.cancelSchedules(Schedule.TYPE_ACTION); return ActionResult.newEmptyResult(); } JsonValue groupsJson = jsonValue.optMap().opt(GROUPS); if (groupsJson.isString()) { automation.cancelScheduleGroup(groupsJson.optString()); } else if (groupsJson.isJsonList()) { for (JsonValue value : groupsJson.optList()) { if (value.isString()) { automation.cancelScheduleGroup(value.optString()); } } } JsonValue idsJson = jsonValue.optMap().opt(IDS); if (idsJson.isString()) { automation.cancelSchedule(idsJson.optString()); } else if (idsJson.isJsonList()) { for (JsonValue value : idsJson.optList()) { if (value.isString()) { automation.cancelSchedule(value.optString()); } } } return ActionResult.newEmptyResult(); } CancelSchedulesAction(); @VisibleForTesting  CancelSchedulesAction(@NonNull Callable<InAppAutomation> actionAutomationCallable); }
CancelSchedulesAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { InAppAutomation automation; try { automation = actionAutomationCallable.call(); } catch (Exception e) { return ActionResult.newErrorResult(e); } JsonValue jsonValue = arguments.getValue().toJsonValue(); if (jsonValue.isString() && ALL.equalsIgnoreCase(jsonValue.getString())) { automation.cancelSchedules(Schedule.TYPE_ACTION); return ActionResult.newEmptyResult(); } JsonValue groupsJson = jsonValue.optMap().opt(GROUPS); if (groupsJson.isString()) { automation.cancelScheduleGroup(groupsJson.optString()); } else if (groupsJson.isJsonList()) { for (JsonValue value : groupsJson.optList()) { if (value.isString()) { automation.cancelScheduleGroup(value.optString()); } } } JsonValue idsJson = jsonValue.optMap().opt(IDS); if (idsJson.isString()) { automation.cancelSchedule(idsJson.optString()); } else if (idsJson.isJsonList()) { for (JsonValue value : idsJson.optList()) { if (value.isString()) { automation.cancelSchedule(value.optString()); } } } return ActionResult.newEmptyResult(); } CancelSchedulesAction(); @VisibleForTesting  CancelSchedulesAction(@NonNull Callable<InAppAutomation> actionAutomationCallable); @Override boolean acceptsArguments(@NonNull ActionArguments arguments); @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); }
CancelSchedulesAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { InAppAutomation automation; try { automation = actionAutomationCallable.call(); } catch (Exception e) { return ActionResult.newErrorResult(e); } JsonValue jsonValue = arguments.getValue().toJsonValue(); if (jsonValue.isString() && ALL.equalsIgnoreCase(jsonValue.getString())) { automation.cancelSchedules(Schedule.TYPE_ACTION); return ActionResult.newEmptyResult(); } JsonValue groupsJson = jsonValue.optMap().opt(GROUPS); if (groupsJson.isString()) { automation.cancelScheduleGroup(groupsJson.optString()); } else if (groupsJson.isJsonList()) { for (JsonValue value : groupsJson.optList()) { if (value.isString()) { automation.cancelScheduleGroup(value.optString()); } } } JsonValue idsJson = jsonValue.optMap().opt(IDS); if (idsJson.isString()) { automation.cancelSchedule(idsJson.optString()); } else if (idsJson.isJsonList()) { for (JsonValue value : idsJson.optList()) { if (value.isString()) { automation.cancelSchedule(value.optString()); } } } return ActionResult.newEmptyResult(); } CancelSchedulesAction(); @VisibleForTesting  CancelSchedulesAction(@NonNull Callable<InAppAutomation> actionAutomationCallable); @Override boolean acceptsArguments(@NonNull ActionArguments arguments); @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); @NonNull
    static final String DEFAULT_REGISTRY_NAME; @NonNull
    static final String DEFAULT_REGISTRY_SHORT_NAME; @NonNull
    static final String GROUPS; @NonNull
    static final String IDS; @NonNull
    static final String ALL; }