Created
May 13, 2020 18:38
-
-
Save Ikhiloya/a82e509e10d062303d691bbb9e7d042d to your computer and use it in GitHub Desktop.
Factory that creates the various strategy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| public class StorageFactory { | |
| private final Logger log = LoggerFactory.getLogger(StorageFactory.class); | |
| private final Environment environment; | |
| private final AwsStorageStrategy awsStorageStrategy; | |
| private final FileStorageStrategy fileStorageStrategy; | |
| public StorageFactory(Environment environment, AwsStorageStrategy awsStorageStrategy, FileStorageStrategy fileStorageStrategy) { | |
| this.environment = environment; | |
| this.awsStorageStrategy = awsStorageStrategy; | |
| this.fileStorageStrategy = fileStorageStrategy; | |
| } | |
| public StorageStrategy createStrategy() { | |
| String[] activeProfiles = environment.getActiveProfiles(); | |
| log.info("Active profiles '{}'", Arrays.toString(activeProfiles)); | |
| if (Arrays.stream(environment.getActiveProfiles()).anyMatch( | |
| env -> (env.equalsIgnoreCase(Constant.DEV_PROFILE)))) { | |
| return this.fileStorageStrategy; | |
| } else if (Arrays.stream(environment.getActiveProfiles()).anyMatch( | |
| env -> (env.equalsIgnoreCase(Constant.PROD_PROFILE)))) { | |
| return this.awsStorageStrategy; | |
| } else { | |
| return this.fileStorageStrategy; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment