SlaOption { public Object toWebObject() { final HashMap<String, Object> slaObj = new HashMap<>(); if (this.type.getComponent() == SlaType.ComponentType.FLOW) { slaObj.put(WEB_ID, ""); } else { slaObj.put(WEB_ID, this.jobName); } slaObj.put(WEB_DURATION, durationToString(this.duration)); slaObj.put(WEB_STATUS, this.type.getStatus().toString()); final List<String> actionsObj = new ArrayList<>(); if (hasAlert()) { actionsObj.add(WEB_ACTION_EMAIL); } if (hasKill()) { actionsObj.add(WEB_ACTION_KILL); } slaObj.put(WEB_ACTIONS, actionsObj); return slaObj; } SlaOption(final SlaType type,
      String flowName, String jobName, Duration duration, Set<SlaAction> actions,
      List<String> emails);  SlaOption(SlaOptionDeprecated slaOption); static List<Object> convertToObjects(List<SlaOption> slaOptions); SlaType getType(); String getJobName(); Duration getDuration(); boolean hasAlert(); boolean hasKill(); String getFlowName(); List<String> getEmails(); boolean isComponentType(SlaType.ComponentType componentType); Map<String, Object> toObject(); String toJSON(); static SlaOption fromObject(Object json); Object toWebObject(); String createSlaMessage(final ExecutableFlow flow); static List<SlaOption> getJobLevelSLAOptions(List<SlaOption> options); static List<SlaOption> getFlowLevelSLAOptions(List<SlaOption> options); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static final String ALERT_TYPE_EMAIL; static final String ACTION_CANCEL_FLOW; static final String ACTION_ALERT; static final String ACTION_KILL_JOB; static final String WEB_ID; static final String WEB_DURATION; static final String WEB_STATUS; static final String WEB_ACTIONS; static final String WEB_ACTION_EMAIL; static final String WEB_ACTION_KILL; }
@Test public void testWebObject() { final String expectedDuration = "60m"; final String expectedStatus = "FINISH"; final String expectedId = "job"; final List<String> expectedAction = Collections.singletonList(SlaOption.WEB_ACTION_KILL); SlaOption slaOption = new SlaOptionBuilder(SlaType.JOB_FINISH, "flow", Duration.ofHours(1)) .setJobName("job").setActions(Collections.singleton(SlaAction.KILL)) .setEmails(Collections.singletonList("test@email.com")).createSlaOption(); Map<String, Object> webObject = (Map<String, Object>)slaOption.toWebObject(); assertThat((String)webObject.get(SlaOption.WEB_DURATION)).isEqualTo(expectedDuration); assertThat((String)webObject.get(SlaOption.WEB_STATUS)).isEqualTo(expectedStatus); assertThat((String)webObject.get(SlaOption.WEB_ID)).isEqualTo(expectedId); assertThat((List<String>)webObject.get(SlaOption.WEB_ACTIONS)).isEqualTo(expectedAction); }