1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.resources.setup; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.HierarchyManager; |
37 |
|
import info.magnolia.cms.core.ItemType; |
38 |
|
import info.magnolia.cms.util.ContentUtil; |
39 |
|
import info.magnolia.cms.util.DateUtil; |
40 |
|
import info.magnolia.module.InstallContext; |
41 |
|
import info.magnolia.module.delta.AbstractRepositoryTask; |
42 |
|
import info.magnolia.module.delta.TaskExecutionException; |
43 |
|
|
44 |
|
import java.util.Calendar; |
45 |
|
|
46 |
|
import javax.jcr.RepositoryException; |
47 |
|
|
48 |
|
import org.apache.commons.lang3.StringUtils; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@author |
54 |
|
@version |
55 |
|
|
56 |
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 14 |
Complexity Density: 0.52 |
|
57 |
|
public class BackupResourceTask extends AbstractRepositoryTask { |
58 |
|
|
59 |
|
public final static String DEFAULT_BACKUP_PATH = "/backup"; |
60 |
|
public final static String WORKSPACE = "resources"; |
61 |
|
public final static String DEFAULT_TIMESTAMP_FORMAT = "'date'-yyyy-MM-dd-'time'-kk-mm-ss-SSSS"; |
62 |
|
|
63 |
|
public final static boolean MOVE_ORIGIN_NODE = true; |
64 |
|
public final static boolean COPY_ORIGIN_NODE = false; |
65 |
|
public final static boolean DEFAULT_ORIGIN_NODE_ACTION = MOVE_ORIGIN_NODE; |
66 |
|
public final static boolean ADD_TIMESTAMP = false; |
67 |
|
public final static boolean NO_TIMESTAMP = true; |
68 |
|
public final static boolean DEFAULT_TIMESTAMP_ACTION = ADD_TIMESTAMP; |
69 |
|
|
70 |
|
private final String resourcePath; |
71 |
|
private final String backupPath; |
72 |
|
private final boolean moveOrigin; |
73 |
|
private final boolean noTimeStamp; |
74 |
|
private final String timeStampFormat; |
75 |
|
|
76 |
|
|
77 |
|
@param |
78 |
|
@param |
79 |
|
@param |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
public BackupResourceTask(String name, String description, String resourcePath) {... |
82 |
0 |
this(name, description, resourcePath, DEFAULT_BACKUP_PATH, DEFAULT_ORIGIN_NODE_ACTION, DEFAULT_TIMESTAMP_ACTION, DEFAULT_TIMESTAMP_FORMAT); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
@param |
88 |
|
@param |
89 |
|
@param |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, boolean moveOrigin) {... |
92 |
0 |
this(name, description, resourcePath, DEFAULT_BACKUP_PATH, moveOrigin, DEFAULT_TIMESTAMP_ACTION, DEFAULT_TIMESTAMP_FORMAT); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
@param |
98 |
|
@param |
99 |
|
@param |
100 |
|
@param |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, boolean moveOrigin, String timeStampFormat) {... |
103 |
0 |
this(name, description, resourcePath, DEFAULT_BACKUP_PATH, moveOrigin, DEFAULT_TIMESTAMP_ACTION, timeStampFormat); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
@param |
108 |
|
@param |
109 |
|
@param |
110 |
|
@param |
111 |
|
@param |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, boolean moveOrigin, boolean noTimeStamp) {... |
114 |
0 |
this(name, description, resourcePath, DEFAULT_BACKUP_PATH, moveOrigin, noTimeStamp, DEFAULT_TIMESTAMP_FORMAT); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
@param |
119 |
|
@param |
120 |
|
@param |
121 |
|
@param |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, String backupPath) {... |
124 |
0 |
this(name, description, resourcePath, backupPath, DEFAULT_ORIGIN_NODE_ACTION, DEFAULT_TIMESTAMP_ACTION, DEFAULT_TIMESTAMP_FORMAT); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
@param |
130 |
|
@param |
131 |
|
@param |
132 |
|
@param |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, String backupPath, boolean moveOrigin) {... |
135 |
0 |
this(name, description, resourcePath, backupPath, moveOrigin, DEFAULT_TIMESTAMP_ACTION, DEFAULT_TIMESTAMP_FORMAT); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
@param |
141 |
|
@param |
142 |
|
@param |
143 |
|
@param |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, String backupPath, String timeStampFormat) {... |
146 |
0 |
this(name, description, resourcePath, backupPath, DEFAULT_ORIGIN_NODE_ACTION, DEFAULT_TIMESTAMP_ACTION, timeStampFormat); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
@param |
151 |
|
@param |
152 |
|
@param |
153 |
|
@param |
154 |
|
@param |
155 |
|
@param |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, String backupPath, boolean moveOrigin, String timeStampFormat) {... |
158 |
0 |
this(name, description, resourcePath, backupPath, moveOrigin, DEFAULT_TIMESTAMP_ACTION, timeStampFormat); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
@param |
163 |
|
@param |
164 |
|
@param |
165 |
|
@param |
166 |
|
@param |
167 |
|
@param |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
0 |
public BackupResourceTask(String name, String description, String resourcePath, String backupPath, boolean moveOrigin, boolean noTimeStamp) {... |
170 |
0 |
this(name, description, resourcePath, backupPath, moveOrigin, noTimeStamp, DEFAULT_TIMESTAMP_FORMAT); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
@param |
177 |
|
@param |
178 |
|
@param |
179 |
|
@param |
180 |
|
@param |
181 |
|
@param |
182 |
|
@param |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
184 |
0 |
private BackupResourceTask(String name, String description, String resourcePath, String backupPath, boolean moveOrigin, boolean noTimeStamp, String timeStampFormat) {... |
185 |
0 |
super(name, description); |
186 |
0 |
this.resourcePath = StringUtils.removeEnd(resourcePath, "/"); |
187 |
0 |
this.backupPath = StringUtils.removeEnd(backupPath, "/"); |
188 |
0 |
this.moveOrigin = moveOrigin; |
189 |
0 |
this.noTimeStamp = noTimeStamp; |
190 |
0 |
this.timeStampFormat = timeStampFormat; |
191 |
|
} |
192 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
193 |
0 |
@Override... |
194 |
|
protected void doExecute(InstallContext installContext) throws TaskExecutionException, RepositoryException { |
195 |
0 |
final HierarchyManager hm = installContext.getHierarchyManager(WORKSPACE); |
196 |
|
|
197 |
0 |
String fullBackupPath = backupPath + resourcePath; |
198 |
|
|
199 |
|
|
200 |
0 |
if(!noTimeStamp){ |
201 |
0 |
fullBackupPath = addTimestampFolder(backupPath) + resourcePath; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
0 |
ContentUtil.createPath(hm, fullBackupPath, ItemType.FOLDER, false); |
206 |
|
|
207 |
|
|
208 |
0 |
hm.delete(fullBackupPath); |
209 |
|
|
210 |
|
|
211 |
0 |
if(moveOrigin){ |
212 |
0 |
ContentUtil.moveInSession(hm.getContent(resourcePath), fullBackupPath); |
213 |
|
} else{ |
214 |
0 |
ContentUtil.copyInSession(hm.getContent(resourcePath), fullBackupPath); |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
@param |
220 |
|
@return@param |
221 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
222 |
0 |
private String addTimestampFolder(String backupPath) {... |
223 |
0 |
String date = DateUtil.format(Calendar.getInstance().getTime(), timeStampFormat); |
224 |
0 |
backupPath += "/"+ date; |
225 |
0 |
return backupPath; |
226 |
|
} |
227 |
|
} |