@@ -110,6 +110,11 @@ public BucketLayout getBucketLayout() {
110110 * @throws OMException if the validation fails
111111 */
112112 public void valid () throws OMException {
113+ validateFields (volume , bucket , rules , bucketLayout , creationTime );
114+ }
115+
116+ private static void validateFields (String volume , String bucket , List <OmLCRule > rules ,
117+ BucketLayout bucketLayout , long creationTime ) throws OMException {
113118 if (StringUtils .isBlank (volume )) {
114119 throw new OMException ("Invalid lifecycle configuration: Volume cannot be blank." ,
115120 OMException .ResultCodes .INVALID_REQUEST );
@@ -130,7 +135,7 @@ public void valid() throws OMException {
130135 + LC_MAX_RULES + " rules" , OMException .ResultCodes .INVALID_REQUEST );
131136 }
132137
133- if (!hasNoDuplicateID ()) {
138+ if (!hasNoDuplicateID (rules )) {
134139 throw new OMException ("Invalid lifecycle configuration: Duplicate rule IDs found." ,
135140 OMException .ResultCodes .INVALID_REQUEST );
136141 }
@@ -140,7 +145,7 @@ public void valid() throws OMException {
140145 }
141146 }
142147
143- private boolean hasNoDuplicateID () {
148+ private static boolean hasNoDuplicateID (List < OmLCRule > rules ) {
144149 return rules .size () == rules .stream ()
145150 .map (OmLCRule ::getId )
146151 .collect (Collectors .toSet ())
@@ -315,46 +320,12 @@ public Builder setUpdateID(long uID) {
315320 protected void validate () {
316321 super .validate ();
317322 try {
318- if (StringUtils .isBlank (volume )) {
319- throw new OMException ("Invalid lifecycle configuration: Volume cannot be blank." ,
320- OMException .ResultCodes .INVALID_REQUEST );
321- }
322-
323- if (StringUtils .isBlank (bucket )) {
324- throw new OMException ("Invalid lifecycle configuration: Bucket cannot be blank." ,
325- OMException .ResultCodes .INVALID_REQUEST );
326- }
327-
328- if (rules .isEmpty ()) {
329- throw new OMException ("At least one rules needs to be specified in a lifecycle configuration." ,
330- OMException .ResultCodes .INVALID_REQUEST );
331- }
332-
333- if (rules .size () > LC_MAX_RULES ) {
334- throw new OMException ("The number of lifecycle rules must not exceed the allowed limit of "
335- + LC_MAX_RULES + " rules" , OMException .ResultCodes .INVALID_REQUEST );
336- }
337-
338- if (!hasNoDuplicateID ()) {
339- throw new OMException ("Invalid lifecycle configuration: Duplicate rule IDs found." ,
340- OMException .ResultCodes .INVALID_REQUEST );
341- }
342-
343- for (OmLCRule rule : rules ) {
344- rule .valid (bucketLayout , creationTime );
345- }
323+ validateFields (volume , bucket , rules , bucketLayout , creationTime );
346324 } catch (OMException e ) {
347325 throw new IllegalArgumentException (e .getMessage (), e );
348326 }
349327 }
350328
351- private boolean hasNoDuplicateID () {
352- return rules .size () == rules .stream ()
353- .map (OmLCRule ::getId )
354- .collect (Collectors .toSet ())
355- .size ();
356- }
357-
358329 @ Override
359330 protected OmLifecycleConfiguration buildObject () {
360331 return new OmLifecycleConfiguration (this );
0 commit comments