All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.bekk.dbscheduler.ui.model.TaskModel Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
/*
 * Copyright (C) Bekk
 *
 * 

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * *

http://www.apache.org/licenses/LICENSE-2.0 * *

Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package no.bekk.dbscheduler.ui.model; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.time.Instant; import java.util.List; import java.util.stream.Collectors; public class TaskModel { private String taskName; private List taskInstance; private List taskData; private List executionTime; private List picked; private List pickedBy; private List lastSuccess; private Instant lastFailure; private List consecutiveFailures; private Instant lastHeartbeat; private int version; private static final ObjectMapper objectMapper = new ObjectMapper(); public TaskModel( String taskName, List taskInstance, List inputTaskData, List executionTime, List picked, List pickedBy, List lastSuccess, Instant lastFailure, List consecutiveFailures, Instant lastHeartbeat, int version) { this.taskName = taskName; this.taskInstance = taskInstance; this.taskData = serializeTaskData(inputTaskData); this.executionTime = executionTime; this.picked = picked; this.pickedBy = pickedBy; this.lastSuccess = lastSuccess; this.lastFailure = lastFailure; this.consecutiveFailures = consecutiveFailures; this.lastHeartbeat = lastHeartbeat; this.version = version; } public TaskModel() {} private List serializeTaskData(List inputTaskDataList) { return inputTaskDataList.stream() .map( data -> { try { String serializedData = objectMapper.writeValueAsString(data); return objectMapper.readValue(serializedData, Object.class); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }) .collect(Collectors.toList()); } public String getTaskName() { return taskName; } public List getTaskInstance() { return taskInstance; } public void setTaskInstance(List taskInstance) { this.taskInstance = taskInstance; } public List getTaskData() { return taskData; } public void setTaskData(List inputTaskData) { this.taskData = serializeTaskData(inputTaskData); } public void setExecutionTime(List executionTime) { this.executionTime = executionTime; } public List getExecutionTime() { return executionTime; } public List isPicked() { return picked; } public void setPicked(List picked) { this.picked = picked; } public List getPickedBy() { return pickedBy; } public void setPickedBy(List pickedBy) { this.pickedBy = pickedBy; } public List getLastSuccess() { return lastSuccess; } public void setLastSuccess(List lastSuccess) { this.lastSuccess = lastSuccess; } public Instant getLastFailure() { return lastFailure; } public void setLastFailure(Instant lastFailure) { this.lastFailure = lastFailure; } public List getConsecutiveFailures() { return consecutiveFailures; } public Instant getLastHeartbeat() { return lastHeartbeat; } public void setLastHeartbeat(Instant lastHeartbeat) { this.lastHeartbeat = lastHeartbeat; } public int getVersion() { return version; } public void setConsecutiveFailures(List consecutiveFailures) { this.consecutiveFailures = consecutiveFailures; } }