1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.execute;
17
18 import org.kuali.common.util.Assert;
19 import org.kuali.common.util.CollectionUtils;
20 import org.kuali.common.util.FormatUtils;
21 import org.kuali.common.util.scm.ScmRequest;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25
26
27
28 @Deprecated
29 public class ScmExecutable implements Executable {
30
31 private static final Logger logger = LoggerFactory.getLogger(ScmExecutable.class);
32
33 boolean skip;
34 boolean logConfiguration;
35 org.kuali.common.util.service.ScmService service;
36 ScmRequest request;
37
38 @Override
39 public void execute() {
40
41
42 if (logConfiguration) {
43 log(this);
44 }
45
46
47 if (skip) {
48 logger.info("Skipping execution");
49 return;
50 }
51
52
53 Assert.notNull(request);
54
55
56 if (isEmpty(request)) {
57 logger.info("Skipping execution. Nothing to do!");
58 return;
59 }
60
61
62 validateConfiguration(service, request);
63
64
65 if (!CollectionUtils.isEmpty(request.getAdds())) {
66 service.add(request.getAdds());
67 }
68
69
70 if (!CollectionUtils.isEmpty(request.getDeletes())) {
71 service.delete(request.getDeletes());
72 }
73
74
75 if (!CollectionUtils.isEmpty(request.getCommits())) {
76 service.commit(request.getCommits(), request.getCommitMessage());
77 }
78 }
79
80 protected void validateConfiguration(org.kuali.common.util.service.ScmService service, ScmRequest request) {
81
82 Assert.notNull(service, "service is null");
83 if (!CollectionUtils.isEmpty(request.getCommits())) {
84 Assert.hasText(request.getCommitMessage(), "commitMessage has no text");
85 }
86 }
87
88 protected void log(ScmExecutable exec) {
89 ScmRequest request = org.kuali.common.util.ScmUtils.cloneOrNew(exec.getRequest());
90 String adds = FormatUtils.getCount(CollectionUtils.toEmptyList(request.getAdds()).size());
91 String deletes = FormatUtils.getCount(CollectionUtils.toEmptyList(request.getDeletes()).size());
92 String commits = FormatUtils.getCount(CollectionUtils.toEmptyList(request.getCommits()).size());
93
94 logger.info(" -- SCM --");
95 logger.info("Adds: {}", adds);
96 logger.info("Deletes: {}", deletes);
97 logger.info("Commits: {}", commits);
98 logger.info("Skip: {}", skip);
99 }
100
101 public boolean isEmpty(ScmRequest request) {
102 if (!CollectionUtils.isEmpty(request.getAdds())) {
103 return false;
104 }
105 if (!CollectionUtils.isEmpty(request.getDeletes())) {
106 return false;
107 }
108 if (!CollectionUtils.isEmpty(request.getCommits())) {
109 return false;
110 }
111 return true;
112 }
113
114 public org.kuali.common.util.service.ScmService getService() {
115 return service;
116 }
117
118 public void setService(org.kuali.common.util.service.ScmService service) {
119 this.service = service;
120 }
121
122 public boolean isSkip() {
123 return skip;
124 }
125
126 public void setSkip(boolean skip) {
127 this.skip = skip;
128 }
129
130 public ScmRequest getRequest() {
131 return request;
132 }
133
134 public void setRequest(ScmRequest request) {
135 this.request = request;
136 }
137
138 public boolean isLogConfiguration() {
139 return logConfiguration;
140 }
141
142 public void setLogConfiguration(boolean logConfiguration) {
143 this.logConfiguration = logConfiguration;
144 }
145
146 }