001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.oozie;
020
021import org.apache.oozie.client.CoordinatorWfAction;
022import org.apache.oozie.client.rest.JsonBean;
023import org.apache.oozie.client.rest.JsonTags;
024import org.json.simple.JSONObject;
025
026public class CoordinatorWfActionBean implements CoordinatorWfAction, JsonBean{
027
028    private int actionNumber;
029
030    private WorkflowActionBean action;
031
032    private String strNullReason;
033
034    public CoordinatorWfActionBean(int actionNumber) {
035        this(actionNumber, null, null);
036    }
037
038    public CoordinatorWfActionBean(int actionNumber, WorkflowActionBean action, String nullReason) {
039        this.actionNumber = actionNumber;
040        this.action = action;
041        this.strNullReason = nullReason;
042    }
043
044    public int getActionNumber() {
045        return actionNumber;
046    }
047
048    public WorkflowActionBean getAction() {
049        return action;
050    }
051
052    public String getNullReason() {
053        return strNullReason;
054    }
055
056    public void setActionNumber(int actionNumber) {
057        this.actionNumber = actionNumber;
058    }
059
060    public void setAction(WorkflowActionBean action) {
061        this.action = action;
062    }
063
064    public void setNullReason(String nullReason) {
065        this.strNullReason = nullReason;
066    }
067
068    @Override
069    public JSONObject toJSONObject() {
070        return toJSONObject("GMT");
071    }
072
073    @Override
074    public JSONObject toJSONObject(String timeZoneId) {
075        JSONObject json = new JSONObject();
076        json.put(JsonTags.COORDINATOR_WF_ACTION_NUMBER, actionNumber);
077        json.put(JsonTags.COORDINATOR_WF_ACTION_NULL_REASON, strNullReason);
078        if (action != null) {
079            json.put(JsonTags.COORDINATOR_WF_ACTION, action.toJSONObject(timeZoneId));
080        }
081        else {
082            json.put(JsonTags.COORDINATOR_WF_ACTION, action);
083        }
084        return json;
085    }
086}