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

com.sap.cloud.mt.subscription.ServiceOperation Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
/*******************************************************************************
 *   © 2019-2024 SAP SE or an SAP affiliate company. All rights reserved.
 ******************************************************************************/
package com.sap.cloud.mt.subscription;

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

/**
 * Service binding parameters
 */
public class ServiceOperation extends HashMap {
    public static final String STATE = "state";
    public static final String TYPE = "type";

    public ServiceOperation(Map m) {
        super(!m.isEmpty() ? m : new HashMap());
    }

    public String getId() {
        return (String) get("id");
    }

    public boolean isReady() {
        return containsKey("ready") && (boolean) get("ready");
    }

    public String getState() {
        return (String) get("state");
    }

    public String getResourceId() {
        return (String) get("resource_id");
    }

    public String getResourceType() {
        return (String) get("resource_type");
    }

    public String getCreatedAt() {
        return (String) get("created_at");
    }

    public String getUpdatedAt() {
        return (String) get("updated_at");
    }

    public Map getErrors() {
        return (Map) get("errors");
    }

    public Type getType() {
        if (!containsKey(TYPE)) {
            return Type.UNDEFINED;
        }
        return switch ((String) get(TYPE)) {
            case "create" -> Type.CREATE;
            case "delete" -> Type.DELETE;
            case "update" -> Type.UPDATE;
            default -> Type.UNDEFINED;
        };
    }

    public Status getStatus() {
        if (!containsKey(STATE)) {
            return Status.IN_PROGRESS;
        }
        return switch ((String) get(STATE)) {
            case "succeeded" -> Status.SUCCEEDED;
            case "failed" -> Status.FAILED;
            default -> Status.IN_PROGRESS;
        };
    }

    public enum Status {
        SUCCEEDED, FAILED, IN_PROGRESS, UNDEFINED
    }

    public enum Type {
        CREATE, DELETE, UPDATE, UNDEFINED
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy