1 package com.trendmicro.grid.acl.ds.dummy;
2
3 import com.trendmicro.grid.acl.commons.Paths;
4 import com.trendmicro.grid.acl.commons.XmlSerializer;
5 import com.trendmicro.grid.acl.ds.ProcessingInitiator;
6 import com.trendmicro.grid.acl.ds.ProcessingResultReceiver;
7 import com.trendmicro.grid.acl.l0.datatypes.ProcessPackageDataSet;
8 import org.springframework.stereotype.Service;
9
10 import javax.annotation.PostConstruct;
11 import javax.xml.bind.annotation.XmlType;
12 import java.io.File;
13 import java.util.Collection;
14
15
16
17
18
19
20
21 @Service
22 public class DummyProcessingImplementation implements ProcessingResultReceiver, ProcessingInitiator {
23
24 private static final XmlSerializer<ProcessPackageDataSet> xmlSerializer =
25 new XmlSerializer<ProcessPackageDataSet>(
26 ProcessPackageDataSet.class,
27 ProcessPackageDataSet.class.getAnnotation(XmlType.class).namespace(),
28 "process-dataset");
29
30 File storagePath;
31
32 @PostConstruct
33 private void init() {
34 storagePath = new File(Paths.getResourcePath(), "dummy-processing-store");
35 if (!storagePath.isDirectory())
36 storagePath.mkdir();
37 }
38
39
40
41
42 public void receive(Collection<ProcessPackageDataSet> dataSets) {
43 try {
44 for (ProcessPackageDataSet dataSet : dataSets) {
45 xmlSerializer.save(dataSet,
46 new File(storagePath, "received-" + dataSet.getReferringJob() + ".xml"), false, 4);
47 }
48 } catch (Exception e) {
49 throw new RuntimeException(e);
50 }
51 }
52
53
54
55
56 public void checkpoint() {
57
58 }
59
60
61
62
63 public void initiate(ProcessPackageDataSet dataSet) {
64 try {
65 xmlSerializer.save(dataSet,
66 new File(storagePath, "initiated-" + dataSet.getReferringJob() + ".xml"), false, 4);
67 } catch (Exception e) {
68 throw new RuntimeException(e);
69 }
70 }
71 }