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
18 #include <alibabacloud/oss/model/LifecycleRule.h>
19
20 using namespace AlibabaCloud::OSS;
21
LifeCycleExpiration()22 LifeCycleExpiration::LifeCycleExpiration() :
23 LifeCycleExpiration(0)
24 {
25 }
26
LifeCycleExpiration(uint32_t days)27 LifeCycleExpiration::LifeCycleExpiration(uint32_t days) :
28 days_(days),
29 createdBeforeDate_()
30 {
31 }
32
LifeCycleExpiration(const std::string & createdBeforeDate)33 LifeCycleExpiration::LifeCycleExpiration(const std::string &createdBeforeDate) :
34 days_(0),
35 createdBeforeDate_(createdBeforeDate)
36 {
37 }
38
setDays(uint32_t days)39 void LifeCycleExpiration::setDays(uint32_t days)
40 {
41 days_ = days;
42 createdBeforeDate_.clear();
43 }
44
setCreatedBeforeDate(const std::string & date)45 void LifeCycleExpiration::setCreatedBeforeDate(const std::string &date)
46 {
47 createdBeforeDate_ = date;
48 days_ = 0;
49 }
50
LifeCycleTransition(const LifeCycleExpiration & expiration,AlibabaCloud::OSS::StorageClass storageClass)51 LifeCycleTransition::LifeCycleTransition(const LifeCycleExpiration& expiration, AlibabaCloud::OSS::StorageClass storageClass) :
52 expiration_(expiration),
53 storageClass_(storageClass)
54 {
55 }
56
setExpiration(const LifeCycleExpiration & expiration)57 void LifeCycleTransition::setExpiration(const LifeCycleExpiration &expiration)
58 {
59 expiration_ = expiration;
60 }
61
setStorageClass(AlibabaCloud::OSS::StorageClass storageClass)62 void LifeCycleTransition::setStorageClass(AlibabaCloud::OSS::StorageClass storageClass)
63 {
64 storageClass_ = storageClass;
65 }
66
LifecycleRule()67 LifecycleRule::LifecycleRule() :
68 status_(RuleStatus::Enabled),
69 expiredObjectDeleteMarker_(false)
70 {
71 }
72
hasExpiration() const73 bool LifecycleRule::hasExpiration() const
74 {
75 return (expiration_.Days() > 0 ||
76 !expiration_.CreatedBeforeDate().empty() ||
77 expiredObjectDeleteMarker_);
78 }
79
hasTransitionList() const80 bool LifecycleRule::hasTransitionList() const
81 {
82 return !transitionList_.empty();
83 }
84
hasAbortMultipartUpload() const85 bool LifecycleRule::hasAbortMultipartUpload() const
86 {
87 return (abortMultipartUpload_.Days() > 0 || !abortMultipartUpload_.CreatedBeforeDate().empty());
88 }
89
hasNoncurrentVersionExpiration() const90 bool LifecycleRule::hasNoncurrentVersionExpiration() const
91 {
92 return (noncurrentVersionExpiration_.Days() > 0);
93 }
94
hasNoncurrentVersionTransitionList() const95 bool LifecycleRule::hasNoncurrentVersionTransitionList() const
96 {
97 return !noncurrentVersionTransitionList_.empty();
98 }
99
operator ==(const LifecycleRule & right) const100 bool LifecycleRule::operator==(const LifecycleRule& right) const
101 {
102 if (id_ != right.id_ ||
103 prefix_ != right.prefix_ ||
104 status_ != right.status_) {
105 return false;
106 }
107
108 if (expiration_.Days() != right.expiration_.Days() ||
109 expiration_.CreatedBeforeDate() != right.expiration_.CreatedBeforeDate()) {
110 return false;
111 }
112
113 if (abortMultipartUpload_.Days() != right.abortMultipartUpload_.Days() ||
114 abortMultipartUpload_.CreatedBeforeDate() != right.abortMultipartUpload_.CreatedBeforeDate()) {
115 return false;
116 }
117
118 if (transitionList_.size() != right.transitionList_.size()) {
119 return false;
120 }
121
122 auto first = transitionList_.begin();
123 auto Rightfirst = right.transitionList_.begin();
124
125 for (; first != transitionList_.end(); ) {
126
127 if (first->Expiration().Days() != Rightfirst->Expiration().Days() ||
128 first->Expiration().CreatedBeforeDate() != Rightfirst->Expiration().CreatedBeforeDate() ||
129 first->StorageClass() != Rightfirst->StorageClass()) {
130 return false;
131 }
132 first++;
133 Rightfirst++;
134 }
135
136 if (tagSet_.size() != right.tagSet_.size()) {
137 return false;
138 }
139
140 auto firstTag = tagSet_.begin();
141 auto RightfirstTag = right.tagSet_.begin();
142
143 for (; firstTag != tagSet_.end(); ) {
144
145 if (firstTag->Key() != RightfirstTag->Key() ||
146 firstTag->Value()!= RightfirstTag->Value()) {
147 return false;
148 }
149 firstTag++;
150 RightfirstTag++;
151 }
152
153 if (expiredObjectDeleteMarker_ != right.expiredObjectDeleteMarker_) {
154 return false;
155 }
156
157 if (noncurrentVersionExpiration_.Days() != right.noncurrentVersionExpiration_.Days() ||
158 noncurrentVersionExpiration_.CreatedBeforeDate() != right.noncurrentVersionExpiration_.CreatedBeforeDate()) {
159 return false;
160 }
161
162 if (noncurrentVersionTransitionList_.size() != right.noncurrentVersionTransitionList_.size()) {
163 return false;
164 }
165
166 first = noncurrentVersionTransitionList_.begin();
167 Rightfirst = right.noncurrentVersionTransitionList_.begin();
168
169 for (; first != noncurrentVersionTransitionList_.end(); ) {
170
171 if (first->Expiration().Days() != Rightfirst->Expiration().Days() ||
172 first->Expiration().CreatedBeforeDate() != Rightfirst->Expiration().CreatedBeforeDate() ||
173 first->StorageClass() != Rightfirst->StorageClass()) {
174 return false;
175 }
176 first++;
177 Rightfirst++;
178 }
179
180 return true;
181 }
182