Skip to content

Commit 3460f17

Browse files
committed
cp
1 parent 331b5e9 commit 3460f17

File tree

5 files changed

+55
-66
lines changed

5 files changed

+55
-66
lines changed

grabbit/src/integrationTest/groovy/com/twcable/grabbit/server/services/ClientServiceSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ClientServiceSpec extends AbstractJcrSpec {
4949
appCtx = new ClassPathXmlApplicationContext(["META-INF/spring/client-batch-job.xml", "META-INF/spring/client-workflow-on-step.xml", "META-INF/spring/client-workflow-off-step.xml"] as String[], parentAppCtx)
5050

5151
syncClientService = new DefaultClientService(slingRepository: slingRepository,
52-
configurableApplicationContext: appCtx)
52+
applicationContext: appCtx)
5353
}
5454

5555

grabbit/src/main/groovy/com/twcable/grabbit/client/batch/ClientBatchJob.groovy

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import groovy.util.logging.Slf4j
2222
import org.springframework.batch.core.BatchStatus
2323
import org.springframework.batch.core.JobExecution
2424
import org.springframework.batch.core.launch.JobOperator
25-
import org.springframework.context.ConfigurableApplicationContext
25+
import org.springframework.context.ApplicationContext
2626

2727
import javax.annotation.Nonnull
2828

@@ -48,7 +48,9 @@ class ClientBatchJob {
4848
public static final String CONTENT_AFTER_DATE = "contentAfterDate"
4949
public static final String DELETE_BEFORE_WRITE = "deleteBeforeWrite"
5050

51+
@SuppressWarnings("GrFinalVariableAccess")
5152
private final Map<String, String> jobParameters
53+
@SuppressWarnings("GrFinalVariableAccess")
5254
private final JobOperator jobOperator
5355

5456

@@ -80,12 +82,12 @@ class ClientBatchJob {
8082

8183
@CompileStatic
8284
static class ServerBuilder {
83-
final ConfigurableApplicationContext configAppContext
85+
final ApplicationContext configAppContext
8486
String host
8587
String port
8688

8789

88-
ServerBuilder(ConfigurableApplicationContext configurableApplicationContext) {
90+
ServerBuilder(ApplicationContext configurableApplicationContext) {
8991
this.configAppContext = configurableApplicationContext
9092
}
9193

@@ -193,16 +195,16 @@ class ClientBatchJob {
193195

194196
ClientBatchJob build() {
195197
final jobParameters = [
196-
"timestamp" : System.currentTimeMillis() as String,
197-
"${PATH}" : pathConfiguration.path,
198-
"${HOST}" : serverBuilder.host,
199-
"${PORT}" : serverBuilder.port,
200-
"${CLIENT_USERNAME}" : credentialsBuilder.clientUsername,
201-
"${SERVER_USERNAME}" : credentialsBuilder.serverUsername,
202-
"${SERVER_PASSWORD}" : credentialsBuilder.serverPassword,
203-
"${EXCLUDE_PATHS}" : pathConfiguration.excludePaths.join("*"),
204-
"${WORKFLOW_CONFIGS}" : pathConfiguration.workflowConfigIds.join("|"),
205-
"${DELETE_BEFORE_WRITE}" : "${pathConfiguration.deleteBeforeWrite}"
198+
"timestamp" : System.currentTimeMillis() as String,
199+
(PATH) : pathConfiguration.path,
200+
(HOST) : serverBuilder.host,
201+
(PORT) : serverBuilder.port,
202+
(CLIENT_USERNAME) : credentialsBuilder.clientUsername,
203+
(SERVER_USERNAME) : credentialsBuilder.serverUsername,
204+
(SERVER_PASSWORD) : credentialsBuilder.serverPassword,
205+
(EXCLUDE_PATHS) : pathConfiguration.excludePaths.join("*"),
206+
(WORKFLOW_CONFIGS) : pathConfiguration.workflowConfigIds.join("|"),
207+
(DELETE_BEFORE_WRITE): "${pathConfiguration.deleteBeforeWrite}"
206208
] as Map<String, String>
207209

208210
if (deltaContentBuilder.doDeltaContent) {
@@ -212,18 +214,15 @@ class ClientBatchJob {
212214
if (lastSuccessFulJobExecution) {
213215
final contentAfterDate = DateUtil.getISOStringFromDate(lastSuccessFulJobExecution.endTime)
214216
log.info "Last Successful run for ${pathConfiguration.path} was on $contentAfterDate"
215-
return new ClientBatchJob(
216-
jobParameters + (["${CONTENT_AFTER_DATE}": contentAfterDate] as Map<String, String>),
217-
serverBuilder.configAppContext.getBean("clientJobOperator", JobOperator)
218-
)
217+
jobParameters.put(CONTENT_AFTER_DATE, contentAfterDate)
219218
}
220219
else {
221220
log.warn "There was no successful job run for $pathConfiguration.path. Defaulting to normal content grab"
222221
}
223222
}
224223
return new ClientBatchJob(
225-
jobParameters,
226-
serverBuilder.configAppContext.getBean("clientJobOperator", JobOperator)
224+
jobParameters,
225+
serverBuilder.configAppContext.getBean("clientJobOperator", JobOperator)
227226
)
228227
}
229228
}

grabbit/src/main/groovy/com/twcable/grabbit/client/services/impl/DefaultClientService.groovy

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import com.twcable.grabbit.client.batch.ClientBatchJob
2222
import com.twcable.grabbit.client.services.ClientService
2323
import groovy.transform.CompileStatic
2424
import groovy.util.logging.Slf4j
25-
import org.apache.felix.scr.annotations.Activate
2625
import org.apache.felix.scr.annotations.Component
2726
import org.apache.felix.scr.annotations.Reference
2827
import org.apache.felix.scr.annotations.Service
2928
import org.apache.sling.jcr.api.SlingRepository
3029
import org.springframework.batch.core.JobExecution
3130
import org.springframework.batch.core.JobInstance
3231
import org.springframework.batch.core.explore.JobExplorer
33-
import org.springframework.context.ConfigurableApplicationContext
32+
import org.springframework.context.ApplicationContext
3433

3534
@Slf4j
3635
@CompileStatic
@@ -44,14 +43,8 @@ class DefaultClientService implements ClientService {
4443
@Reference(bind = 'setSlingRepository')
4544
SlingRepository slingRepository
4645

47-
@Reference(bind = 'setConfigurableApplicationContext')
48-
ConfigurableApplicationContext configurableApplicationContext
49-
50-
51-
@Activate
52-
void activate() {
53-
log.info "Activate\n\n"
54-
}
46+
@Reference(bind = 'setApplicationContext')
47+
ApplicationContext applicationContext
5548

5649

5750
@Override
@@ -67,13 +60,13 @@ class DefaultClientService implements ClientService {
6760

6861
for (PathConfiguration pathConfig : configuration.pathConfigurations) {
6962
try {
70-
final clientBatchJob = new ClientBatchJob.ServerBuilder(configurableApplicationContext)
71-
.andServer(configuration.serverHost, configuration.serverPort)
72-
.andCredentials(clientUsername, configuration.serverUsername, configuration.serverPassword)
73-
.andDoDeltaContent(doDeltaContent)
74-
.andClientJobExecutions(clientJobExecutions)
75-
.andConfiguration(pathConfig)
76-
.build()
63+
final clientBatchJob = new ClientBatchJob.ServerBuilder(applicationContext)
64+
.andServer(configuration.serverHost, configuration.serverPort)
65+
.andCredentials(clientUsername, configuration.serverUsername, configuration.serverPassword)
66+
.andDoDeltaContent(doDeltaContent)
67+
.andClientJobExecutions(clientJobExecutions)
68+
.andConfiguration(pathConfig)
69+
.build()
7770
final Long currentJobExecutionId = clientBatchJob.start()
7871
jobExecutionIds << currentJobExecutionId
7972
}
@@ -88,7 +81,7 @@ class DefaultClientService implements ClientService {
8881

8982

9083
private List<JobExecution> fetchAllClientJobExecutions() {
91-
final explorer = configurableApplicationContext.getBean("clientJobExplorer", JobExplorer)
84+
final explorer = applicationContext.getBean("clientJobExplorer", JobExplorer)
9285
final instances = explorer.getJobInstances("clientJob", 0, Integer.MAX_VALUE - 1) ?: [] as List<JobInstance>
9386
final executions = instances.collect { explorer.getJobExecutions(it) }.flatten() as List<JobExecution>
9487
executions

grabbit/src/main/groovy/com/twcable/grabbit/servlets/GrabbitServlet.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.apache.sling.api.SlingHttpServletRequest
3131
import org.apache.sling.api.SlingHttpServletResponse
3232
import org.apache.sling.api.servlets.SlingAllMethodsServlet
3333
import org.springframework.batch.core.explore.JobExplorer
34-
import org.springframework.context.ConfigurableApplicationContext
34+
import org.springframework.context.ApplicationContext
3535

3636
import javax.servlet.http.HttpServletResponse
3737

@@ -40,8 +40,8 @@ import javax.servlet.http.HttpServletResponse
4040
@SlingServlet(methods = ['GET', 'PUT'], resourceTypes = ['twcable:grabbit/job'])
4141
class GrabbitServlet extends SlingAllMethodsServlet {
4242

43-
@Reference(bind = 'setConfigurableApplicationContext')
44-
ConfigurableApplicationContext configurableApplicationContext
43+
@Reference(bind = 'setApplicationContext')
44+
ApplicationContext applicationContext
4545

4646
@Reference(bind = 'setClientService')
4747
ClientService clientService
@@ -114,7 +114,7 @@ class GrabbitServlet extends SlingAllMethodsServlet {
114114

115115

116116
private String getJsonString(String jobId) {
117-
final JobExplorer jobExplorer = configurableApplicationContext.getBean("clientJobExplorer", JobExplorer)
117+
final JobExplorer jobExplorer = applicationContext.getBean("clientJobExplorer", JobExplorer)
118118
if (jobId.isNumber()) {
119119
//Returns Status for A Job
120120
final ClientJobStatus status = ClientJobStatus.get(jobExplorer, Long.valueOf(jobId))

grabbit/src/test/groovy/com/twcable/grabbit/client/batch/ClientBatchJobSpec.groovy

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,62 +22,59 @@ import org.springframework.batch.core.BatchStatus
2222
import org.springframework.batch.core.JobExecution
2323
import org.springframework.batch.core.JobParametersBuilder
2424
import org.springframework.batch.core.launch.JobOperator
25-
import org.springframework.context.ConfigurableApplicationContext
25+
import org.springframework.context.ApplicationContext
2626
import spock.lang.Shared
2727
import spock.lang.Specification
2828
import spock.lang.Subject
2929
import spock.lang.Unroll
3030

3131
@Subject(ClientBatchJob)
32+
@SuppressWarnings("GroovyAccessibility")
3233
class ClientBatchJobSpec extends Specification {
3334

3435
@Shared
35-
def dateNow
36-
37-
38-
def setupSpec() {
39-
dateNow = new Date()
40-
}
36+
Date dateNow = new Date()
4137

4238

4339
@Unroll
44-
def "Make sure ClientBatch job gets configured correctly"() {
40+
def "Job Params: #path #doDeltaContent #contentAfterDate #deleteBeforeWrite"() {
4541
when:
46-
final appContext = Mock(ConfigurableApplicationContext)
42+
final appContext = Mock(ApplicationContext)
4743
appContext.getBean(_ as String, JobOperator) >> Mock(JobOperator)
4844
final job = new ClientBatchJob.ServerBuilder(appContext)
49-
.andServer("host", "port")
50-
.andCredentials("clientUser", "serverUser", "serverPass")
51-
.andDoDeltaContent(doDeltaContent)
52-
.andClientJobExecutions(jobExecutions)
53-
.andConfiguration(new GrabbitConfiguration.PathConfiguration(path, [], [], deleteBeforeWrite))
54-
.build()
45+
.andServer("host", "port")
46+
.andCredentials("clientUser", "serverUser", "serverPass")
47+
.andDoDeltaContent(doDeltaContent)
48+
.andClientJobExecutions(jobExecutions)
49+
.andConfiguration(new GrabbitConfiguration.PathConfiguration(path, [], [], deleteBeforeWrite))
50+
.build()
5551

5652
then:
5753
job != null
5854
job.jobParameters != null
59-
job.jobParameters.get("${ClientBatchJob.PATH}") == path
60-
job.jobParameters.get("${ClientBatchJob.CONTENT_AFTER_DATE}") == contentAfterDate
61-
job.jobParameters.get("${ClientBatchJob.DELETE_BEFORE_WRITE}").toBoolean() == deleteBeforeWrite
55+
job.jobParameters.get(ClientBatchJob.PATH) == path
56+
job.jobParameters.get(ClientBatchJob.CONTENT_AFTER_DATE) == contentAfterDate
57+
job.jobParameters.get(ClientBatchJob.DELETE_BEFORE_WRITE).toBoolean() == deleteBeforeWrite
6258

6359
where:
64-
doDeltaContent | path | contentAfterDate | deleteBeforeWrite
65-
true | "/path1" | DateUtil.getISOStringFromDate(dateNow) | true
66-
false | "/path1" | null | false
67-
true | "/path2" | null | true
68-
false | "/path2" | null | false
69-
60+
path | doDeltaContent | contentAfterDate | deleteBeforeWrite
61+
"/path1" | true | DateUtil.getISOStringFromDate(dateNow) | true
62+
"/path1" | false | null | false
63+
"/path2" | true | null | true
64+
"/path2" | false | null | false
7065
}
7166

7267

7368
def getJobExecutions() {
7469
def ex1 = new JobExecution(1, new JobParametersBuilder().addString("path", "/path1").toJobParameters())
7570
ex1.endTime = dateNow
7671
ex1.status = BatchStatus.COMPLETED
72+
7773
def ex2 = new JobExecution(2, new JobParametersBuilder().addString("path", "/path2").toJobParameters())
7874
ex2.endTime = dateNow
7975
ex2.status = BatchStatus.FAILED
8076

8177
[ex1, ex2]
8278
}
79+
8380
}

0 commit comments

Comments
 (0)