1 package org.kuali.common.deploy;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.kuali.common.util.Assert;
5 import org.kuali.common.util.LocationUtils;
6 import org.kuali.common.util.nullify.NullUtils;
7
8 import com.google.common.base.Optional;
9
10 public final class Deployable {
11
12 private final String local;
13 private final String remote;
14 private final boolean exists;
15
16 private final boolean filter;
17 private final boolean required;
18 private final Optional<String> permissions;
19
20 public boolean isFilter() {
21 return filter;
22 }
23
24 public String getLocal() {
25 return local;
26 }
27
28 public String getRemote() {
29 return remote;
30 }
31
32 public Optional<String> getPermissions() {
33 return permissions;
34 }
35
36 public boolean isRequired() {
37 return required;
38 }
39
40 public boolean isExists() {
41 return exists;
42 }
43
44 public static class Builder {
45
46 private final String local;
47 private final String remote;
48 private final boolean exists;
49
50 private boolean filter = false;
51 private boolean required = true;
52 private Optional<String> permissions = Optional.absent();
53
54 public Builder(String local, String remote) {
55 this.local = local;
56 this.remote = remote;
57 this.exists = LocationUtils.exists(local);
58 }
59
60 public Builder filter(boolean filter) {
61 this.filter = filter;
62 return this;
63 }
64
65 public Builder required(boolean required) {
66 this.required = required;
67 return this;
68 }
69
70
71
72
73
74 public Builder permissions(String permissions) {
75 if (permissions != null) {
76 Assert.noBlanks(permissions);
77 }
78 String trimmed = StringUtils.trimToNull(permissions);
79 String converted = NullUtils.isNullOrNone(trimmed) ? null : trimmed;
80 this.permissions = Optional.fromNullable(converted);
81 return this;
82 }
83
84 public Deployable build() {
85 Assert.noBlanks(local, remote);
86 Assert.noNulls(permissions);
87 if (required) {
88 Assert.isTrue(exists, "[" + local + "] does not exist");
89 }
90 return new Deployable(this);
91 }
92
93 }
94
95 private Deployable(Builder builder) {
96 this.local = builder.local;
97 this.remote = builder.remote;
98 this.exists = builder.exists;
99 this.filter = builder.filter;
100 this.required = builder.required;
101 this.permissions = builder.permissions;
102 }
103
104 }