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

com.centurylink.mdw.model.task.TaskIndexes Maven / Gradle / Ivy

There is a newer version: 6.1.39
Show newest version
/*
 * Copyright (C) 2017 CenturyLink, Inc.
 *
 * 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 com.centurylink.mdw.model.task;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.centurylink.mdw.model.Jsonable;

public class TaskIndexes implements Jsonable {

    private long taskInstanceId;
    public long getTaskInstanceId() { return taskInstanceId; }

    private Map indexes;
    public Map getIndexes() { return indexes; }

    public String getIndexValue(String key) {
        return indexes.get(key);
    }

    public void setIndexValue(String key, String value) {
        indexes.put(key, value);
    }

    public TaskIndexes(long taskInstanceId) {
        this.taskInstanceId = taskInstanceId;
        indexes = new HashMap();
    }

    public TaskIndexes(long taskInstanceId, Map indexes) {
        this.taskInstanceId = taskInstanceId;
        this.indexes = indexes;
    }

    public TaskIndexes(JSONObject json) throws JSONException {
        taskInstanceId = json.getLong("taskInstanceId");
        indexes = new HashMap();
        if (json.has("indexes")) {
            JSONObject indexJson = json.getJSONObject("indexes");
            String[] names = JSONObject.getNames(indexJson);
            if (names != null) {
                for (String name : names) {
                    indexes.put(name, indexJson.getString(name));
                }
            }
        }
    }

    public JSONObject getJson() throws JSONException {

        JSONObject taskInstance = create();
        taskInstance.put("taskInstanceId", taskInstanceId);

        if (!indexes.isEmpty()) {
            JSONObject indices = create();
            for (String key : indexes.keySet()) {
                indices.put(key, indexes.get(key));
            }
            taskInstance.put("indexes", indices);
        }

        return taskInstance;
    }

    public String getJsonName() {
        return "TaskInstanceIndexes";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy