1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
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  */
16 
17 #include <alibabacloud/oss/model/CreateSelectObjectMetaRequest.h>
18 #include <sstream>
19 #include "ModelError.h"
20 #include "utils/Utils.h"
21 
22 using namespace AlibabaCloud::OSS;
23 
CreateSelectObjectMetaRequest(const std::string & bucket,const std::string & key)24 CreateSelectObjectMetaRequest::CreateSelectObjectMetaRequest(const std::string& bucket, const std::string& key) :
25     OssObjectRequest(bucket, key),
26     inputFormat_(nullptr),
27     overWriteIfExists_(false)
28 {
29     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
30 }
31 
setOverWriteIfExists(bool overWriteIfExists)32 void CreateSelectObjectMetaRequest::setOverWriteIfExists(bool overWriteIfExists)
33 {
34     overWriteIfExists_ = overWriteIfExists;
35 }
36 
setInputFormat(InputFormat & inputFormat)37 void CreateSelectObjectMetaRequest::setInputFormat(InputFormat& inputFormat)
38 {
39     inputFormat_ = &inputFormat;
40 }
41 
payload() const42 std::string CreateSelectObjectMetaRequest::payload() const
43 {
44     std::stringstream ss;
45     if (inputFormat_->Type() == "csv") {
46         ss << "<CsvMetaRequest>" << std::endl;
47         ss << inputFormat_->toXML(0) << std::endl;
48         ss << "<OverwriteIfExists>" << (overWriteIfExists_ ? "true" : "false") << "</OverwriteIfExists>" << std::endl;
49         ss << "</CsvMetaRequest>" << std::endl;
50     }
51     else {
52         ss << "<JsonMetaRequest>" << std::endl;
53         ss << inputFormat_->toXML(0) << std::endl;
54         ss << "<OverwriteIfExists>" << (overWriteIfExists_ ? "true" : "false") << "</OverwriteIfExists>" << std::endl;
55         ss << "</JsonMetaRequest>" << std::endl;
56     }
57     return ss.str();
58 }
59 
validate() const60 int CreateSelectObjectMetaRequest::validate() const
61 {
62     int ret = OssObjectRequest::validate();
63     if (ret != 0) {
64         return ret;
65     }
66     if (inputFormat_ == nullptr) {
67         return ARG_ERROR_CREATE_SELECT_OBJECT_META_NULL_POINT;
68     }
69     return 0;
70 }
71 
specialParameters() const72 ParameterCollection CreateSelectObjectMetaRequest::specialParameters() const
73 {
74     ParameterCollection parameters;
75     if (inputFormat_) {
76         auto type = inputFormat_->Type();
77         type.append("/meta");
78         parameters["x-oss-process"] = type;
79     }
80     return parameters;
81 }
82