.setCreatedBefore(condition.getCreatedBefore()) .setIsLive(condition.getIsLive()) .setNumberOfNewerVersions(condition.getNumNewerVersions()) .setMatchesStorageClass( condition.getMatchesStorageClass() == null
static DeleteRule fromPb(Rule rule) { if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) { Rule.Condition condition = rule.getCondition(); Integer age = condition.getAge(); if (age != null) { return new AgeDeleteRule(age); } DateTime dateTime = condition.getCreatedBefore(); if (dateTime != null) { return new CreatedBeforeDeleteRule(dateTime.getValue()); } Integer numNewerVersions = condition.getNumNewerVersions(); if (numNewerVersions != null) { return new NumNewerVersionsDeleteRule(numNewerVersions); } Boolean isLive = condition.getIsLive(); if (isLive != null) { return new IsLiveDeleteRule(isLive); } } return new RawDeleteRule(rule); } }
@Test public void testLifecycleRules() { Rule deleteLifecycleRule = new LifecycleRule( LifecycleAction.newDeleteAction(), LifecycleCondition.newBuilder().setAge(10).build()) .toPb(); assertEquals( LifecycleRule.DeleteLifecycleAction.TYPE, deleteLifecycleRule.getAction().getType()); assertEquals(10, deleteLifecycleRule.getCondition().getAge().intValue()); Rule setStorageClassLifecycleRule = new LifecycleRule( LifecycleAction.newSetStorageClassAction(StorageClass.COLDLINE), LifecycleCondition.newBuilder() .setIsLive(true) .setNumberOfNewerVersions(10) .build()) .toPb(); assertEquals( StorageClass.COLDLINE.toString(), setStorageClassLifecycleRule.getAction().getStorageClass()); assertTrue(setStorageClassLifecycleRule.getCondition().getIsLive()); assertEquals(10, setStorageClassLifecycleRule.getCondition().getNumNewerVersions().intValue()); } }
.setCreatedBefore(condition.getCreatedBefore()) .setIsLive(condition.getIsLive()) .setNumberOfNewerVersions(condition.getNumNewerVersions()) .setMatchesStorageClass( condition.getMatchesStorageClass() == null
static DeleteRule fromPb(Rule rule) { if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) { Rule.Condition condition = rule.getCondition(); Integer age = condition.getAge(); if (age != null) { return new AgeDeleteRule(age); } DateTime dateTime = condition.getCreatedBefore(); if (dateTime != null) { return new CreatedBeforeDeleteRule(dateTime.getValue()); } Integer numNewerVersions = condition.getNumNewerVersions(); if (numNewerVersions != null) { return new NumNewerVersionsDeleteRule(numNewerVersions); } Boolean isLive = condition.getIsLive(); if (isLive != null) { return new IsLiveDeleteRule(isLive); } } return new RawDeleteRule(rule); } }
static DeleteRule fromPb(Rule rule) { if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) { Rule.Condition condition = rule.getCondition(); Integer age = condition.getAge(); if (age != null) { return new AgeDeleteRule(age); } DateTime dateTime = condition.getCreatedBefore(); if (dateTime != null) { return new CreatedBeforeDeleteRule(dateTime.getValue()); } Integer numNewerVersions = condition.getNumNewerVersions(); if (numNewerVersions != null) { return new NumNewerVersionsDeleteRule(numNewerVersions); } Boolean isLive = condition.getIsLive(); if (isLive != null) { return new IsLiveDeleteRule(isLive); } } return new RawDeleteRule(rule); } }