I am trying of implement a strategy to load from application.properties two values set dinamically depending on condition of income:
# Configuration A
payouts.xxx.by-default.business-name=ABC S.A.S
payouts.xxx.by-default.nit=830109723
payouts.xxx.by-default.account.number=1234567890
payouts.xxx.by-default.account.type=01
payouts.xxx.by-default.account.financial-institute-id=GEROCOBB
payouts.xxx.by-default.BIC=4566
# Configuration B
payouts.xxx.loan.business-name=XYZ S.A.S
payouts.xxx.loan.nit=830109723
payouts.xxx.loan.account.number=1234567890
payouts.xxx.loan.account.type=01
payouts.xxx.loan.account.financial-institute-id=GEROCOBB
payouts.xxx.loan.BIC=344444
So I have 2 class that represented the properties values :
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class AccountConfiguration {
private String businessName;
private String nit;
private String bic;
private Account account;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Account {
private String number;
private String type;
private String financialInstituteId;
}
And also I have other class that represented the configuration class to get the values from application.properties
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Configuration
@ConfigurationProperties(prefix = "payouts.xxx.loan")
public class PayoutAccountConfiguration {
private AccountConfiguration byDefault;
private AccountConfiguration loan;
public AccountConfiguration getConfiguration(String flag) {
if (flag.equals(PayoutOrderStatus.IN_AUTOMATIC)) {
return loan;
}else{
return byDefault;
}
}
}
And for last in the application class I have anotation to enabled the configuration
@SpringBootApplication
@EnableFeignClients
@EnableConfigurationProperties({AccountConfiguration.class, Account.class})
@Import(EncryptedPropertyConfiguration.class)
public class TestApplication {
/**
* The main method to start the application.
* @param args command-line arguments
*/
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
Now I need that in getConfiguration method there are logic to decided depends on income if return the value by default(Configuration A) or the value personalized (Configuration B). I don't know how do these. Can you help me. giving ideas please.