Skip to content

Commit 398ffc3

Browse files
authored
Add preset variable account created (#10200)
1 parent 3b108b9 commit 398ffc3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java

+16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717

1818
package org.apache.cloudstack.quota.activationrule.presetvariables;
1919

20+
import com.cloud.utils.DateUtil;
21+
22+
import java.util.Date;
23+
import java.util.TimeZone;
24+
2025
public class Account extends GenericPresetVariable {
2126
@PresetVariableDefinition(description = "Role of the account. This field will not exist if the account is a project.")
2227

2328
private Role role;
2429

30+
@PresetVariableDefinition(description = "The date the account was created in GMT. This field will not exist for the first root admin account.")
31+
private String created;
32+
2533
public Role getRole() {
2634
return role;
2735
}
@@ -31,4 +39,12 @@ public void setRole(Role role) {
3139
fieldNamesToIncludeInToString.add("role");
3240
}
3341

42+
public String getCreated() {
43+
return created;
44+
}
45+
46+
public void setCreated(Date created) {
47+
this.created = DateUtil.displayDateInTimezone(TimeZone.getTimeZone("GMT"), created);
48+
fieldNamesToIncludeInToString.add("created");
49+
}
3450
}

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ protected Account getPresetVariableAccount(Long accountId) {
224224
Account account = new Account();
225225
account.setId(accountVo.getUuid());
226226
account.setName(accountVo.getName());
227+
account.setCreated(accountVo.getCreated());
227228

228229
setPresetVariableRoleInAccountIfAccountIsNotAProject(accountVo.getType(), accountVo.getRoleId(), account);
229230

framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,12 @@ public void getPresetVariableAccountTestSetValuesAndReturnObject() {
375375
Account account = getAccountForTests();
376376
Mockito.doReturn(account.getId()).when(accountVoMock).getUuid();
377377
Mockito.doReturn(account.getName()).when(accountVoMock).getName();
378+
Mockito.doReturn(account.getCreated()).when(accountVoMock).getCreated();
378379

379380
Account result = presetVariableHelperSpy.getPresetVariableAccount(1l);
380381

381382
assertPresetVariableIdAndName(account, result);
382-
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name"), result);
383+
validateFieldNamesToIncludeInToString(Arrays.asList("created", "id", "name"), result);
383384
}
384385

385386
@Test

0 commit comments

Comments
 (0)