Search in sources :

Example 1 with MediaOperation

use of com.qcloud.cos.model.ciModel.workflow.MediaOperation in project cos-java-sdk-v5 by tencentyun.

the class RequestXmlFactory method convertToXmlByteArray.

/**
 * Converts the MediaWorkflowRequest to an XML fragment that can be sent to the RestoreObject
 * operation of COS.
 *
 * @param request The container which provides options for restoring an object,
 *                which was transitioned to the CAS from COS when it was expired, into COS again.
 * @return A byte array containing the data
 * @throws CosClientException
 */
public static byte[] convertToXmlByteArray(MediaWorkflowRequest request) throws CosClientException, UnsupportedEncodingException {
    XmlWriter xml = new XmlWriter();
    xml.start("Request");
    xml.start("MediaWorkflow");
    xml.start("Name").value(request.getName()).end();
    addIfNotNull(xml, "State", request.getState());
    addIfNotNull(xml, "WorkflowId", request.getWorkflowId());
    xml.start("Topology");
    xml.start("Dependencies");
    Map<String, MediaWorkflowDependency> mediaWorkflowDependency = request.getTopology().getMediaWorkflowDependency();
    for (String key : mediaWorkflowDependency.keySet()) {
        xml.start(key).value(mediaWorkflowDependency.get(key).getValue()).end();
    }
    xml.end();
    xml.start("Nodes");
    Map<String, MediaWorkflowNode> mediaWorkflowNodes = request.getTopology().getMediaWorkflowNodes();
    for (String key : mediaWorkflowNodes.keySet()) {
        xml.start(key);
        MediaWorkflowNode mediaWorkflowNode = mediaWorkflowNodes.get(key);
        xml.start("Type").value(mediaWorkflowNode.getType()).end();
        if (mediaWorkflowNode.getInput().getObjectPrefix() != null || mediaWorkflowNode.getInput().getQueueId() != null) {
            xml.start("Input");
            addIfNotNull(xml, "QueueId", mediaWorkflowNode.getInput().getQueueId());
            addIfNotNull(xml, "ObjectPrefix", mediaWorkflowNode.getInput().getObjectPrefix());
            xml.end();
        }
        MediaOperation operation = mediaWorkflowNode.getOperation();
        MediaOutputObject output = operation.getOutput();
        if (operation.getTemplateId() != null || output.getBucket() != null || output.getObject() != null || output.getRegion() != null) {
            xml.start("Operation");
            addIfNotNull(xml, "TemplateId", operation.getTemplateId());
            xml.start("Output");
            addIfNotNull(xml, "Region", output.getRegion());
            addIfNotNull(xml, "Bucket", output.getBucket());
            addIfNotNull(xml, "Object", output.getObject());
            xml.end();
            xml.end();
        }
        xml.end();
    }
    xml.end();
    xml.end();
    xml.end();
    xml.end();
    return xml.getBytes();
}
Also used : MediaWorkflowDependency(com.qcloud.cos.model.ciModel.workflow.MediaWorkflowDependency) MediaWorkflowNode(com.qcloud.cos.model.ciModel.workflow.MediaWorkflowNode) MediaOperation(com.qcloud.cos.model.ciModel.workflow.MediaOperation) MediaOutputObject(com.qcloud.cos.model.ciModel.common.MediaOutputObject)

Aggregations

MediaOutputObject (com.qcloud.cos.model.ciModel.common.MediaOutputObject)1 MediaOperation (com.qcloud.cos.model.ciModel.workflow.MediaOperation)1 MediaWorkflowDependency (com.qcloud.cos.model.ciModel.workflow.MediaWorkflowDependency)1 MediaWorkflowNode (com.qcloud.cos.model.ciModel.workflow.MediaWorkflowNode)1