View Javadoc
1   package org.kuali.common.devops.jenkins.scan.function;
2   
3   import static org.kuali.common.util.base.Precondition.checkNotBlank;
4   import static org.kuali.common.util.base.Precondition.checkNotNull;
5   
6   import org.kuali.common.aws.s3.S3Service;
7   import org.kuali.common.core.json.api.JsonService;
8   import org.kuali.common.devops.jenkins.scan.Jenkins;
9   
10  import com.google.common.base.Function;
11  
12  public class PreviousJenkinsFunction implements Function<String, Jenkins> {
13  
14  	public PreviousJenkinsFunction(JsonService json, S3Service s3, String bucket) {
15  		this.json = checkNotNull(json, "json");
16  		this.s3 = checkNotNull(s3, "s3");
17  		this.bucket = checkNotBlank(bucket, "bucket");
18  	}
19  
20  	private final JsonService json;
21  	private final S3Service s3;
22  	private final String bucket;
23  
24  	@Override
25  	public Jenkins apply(String key) {
26  		checkNotBlank(key, "key");
27  		if (s3.exists(bucket, key)) {
28  			String text = s3.readObjectToString(bucket, key);
29  			return json.readString(text, Jenkins.class);
30  		} else {
31  			String hostname = System.getProperty("jenkins.hostname", "ci.kuali.org");
32  			String version = System.getProperty("jenkins.version", "1.532.3");
33  			return Jenkins.builder().withHostname(hostname).withVersion(version).build();
34  		}
35  	}
36  
37  	public JsonService getJson() {
38  		return json;
39  	}
40  
41  	public S3Service getS3() {
42  		return s3;
43  	}
44  
45  	public String getBucket() {
46  		return bucket;
47  	}
48  }