blob: 67e18f8dcdc40ae2f296ebedeeb0d7ad98778a06 [file] [log] [blame]
senthilb2760032024-02-24 10:08:30 +09001/*
2 * Copyright 2024-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.workflow.api;
17
18import com.fasterxml.jackson.annotation.JsonAutoDetect;
19
20
21/**
22 * Workflow Information Class for other applications.
23 * it has name, type and step.
24 */
25@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
26public final class WorkflowInfo {
27 private String name;
28 private String type;
29 private int step;
30
31 /**
32 * Constructor of parameters.
33 * @param name Workflow's name
34 * @param type Workflow's type
35 * @param step the number of workflow's worklet
36 */
37 private WorkflowInfo(String name, String type, int step) {
38 this.name = name;
39 this.type = type;
40 this.step = step;
41 }
42
43 /**
44 * Construct method for 'workflow'.
45 * @param workflow workflow to be converted to WorkflowInfo
46 * @return WorkflowInfo object.
47 */
48 public static WorkflowInfo of(Workflow workflow) {
49 return new WorkflowInfo(workflow.id().toString(),
50 createTypeFromWorkletType(workflow.getProgram().get(1).workletType()),
51 workflow.getProgram().size());
52 }
53
54
55 /**
56 * Parsing workflow type using workletType in workflow's worklet descriptions.
57 * @param workletType first workletType in workflow.
58 * @return parsed value.
59 */
60 private static String createTypeFromWorkletType(String workletType) {
61 String[] candidate = workletType.split("\\$")[0].split("\\.");
62 return candidate[candidate.length - 1];
63 }
64}
65