| Line 88... |
Line 88... |
| 88 |
return;
|
88 |
return;
|
| 89 |
} else {
|
89 |
} else {
|
| 90 |
Map<String, Media> medias = expSlide.getFreeformContent().getMedias();
|
90 |
Map<String, Media> medias = expSlide.getFreeformContent().getMedias();
|
| 91 |
for (String documentLabel : documentLabels) {
|
91 |
for (String documentLabel : documentLabels) {
|
| 92 |
Media document = medias.get(documentLabel);
|
92 |
Media document = medias.get(documentLabel);
|
| 93 |
if (document.getCreationTime().getTime() > Long.parseLong(contentVersion)) {
|
- |
|
| 94 |
copyFile(new File(document.getLocation()), new File(destFile, computeNewFileName(documentPrefix, document.getFileName(),
|
93 |
copyFile(new File(document.getLocation()), new File(destFile, computeNewFileName(documentPrefix, document.getFileName(),
|
| 95 |
String.valueOf(document.getCreationTime().getTime()))));
|
94 |
String.valueOf(document.getCreationTime().getTime()))), false);
|
| 96 |
}
|
- |
|
| 97 |
}
|
95 |
}
|
| 98 |
}
|
96 |
}
|
| 99 |
}
|
97 |
}
|
| 100 |
|
98 |
|
| 101 |
/**
|
99 |
/**
|
| Line 127... |
Line 125... |
| 127 |
/*
|
125 |
/*
|
| 128 |
* If the default image is not present for this entity, copy the global
|
126 |
* If the default image is not present for this entity, copy the global
|
| 129 |
* default image. TODO: This part will be moved to the Jython Script
|
127 |
* default image. TODO: This part will be moved to the Jython Script
|
| 130 |
*/
|
128 |
*/
|
| 131 |
File globalDefaultJPGFile = new File(globalDefaultImagePath);
|
129 |
File globalDefaultJPGFile = new File(globalDefaultImagePath);
|
| 132 |
File f3 = new File(defaultImagePath);
|
- |
|
| 133 |
if (!f3.exists()) {
|
- |
|
| 134 |
copyFile(globalDefaultJPGFile, new File(
|
130 |
copyFile(globalDefaultJPGFile, new File(defaultImagePath), false);
|
| 135 |
defaultImagePath));
|
- |
|
| 136 |
}
|
- |
|
| 137 |
|
131 |
|
| 138 |
File staticMediaDirectory = new File(Utils.EXPORT_MEDIA_STATIC_PATH + catalogId);
|
132 |
File staticMediaDirectory = new File(Utils.EXPORT_MEDIA_STATIC_PATH + catalogId);
|
| 139 |
if (!staticMediaDirectory.exists()) {
|
133 |
if (!staticMediaDirectory.exists()) {
|
| 140 |
staticMediaDirectory.mkdir();
|
134 |
staticMediaDirectory.mkdir();
|
| 141 |
}
|
135 |
}
|
| Line 152... |
Line 146... |
| 152 |
*/
|
146 |
*/
|
| 153 |
long defaultImageCreationTime = EntityUtils.getCreationTimeFromSummarySlide(entity, "default");
|
147 |
long defaultImageCreationTime = EntityUtils.getCreationTimeFromSummarySlide(entity, "default");
|
| 154 |
File newVersionedDefaultJPGFile = new File(staticMediaDirectory,
|
148 |
File newVersionedDefaultJPGFile = new File(staticMediaDirectory,
|
| 155 |
computeNewFileName(imagePrefix, DEFAULT_JPG, String.valueOf(defaultImageCreationTime)));
|
149 |
computeNewFileName(imagePrefix, DEFAULT_JPG, String.valueOf(defaultImageCreationTime)));
|
| 156 |
|
150 |
|
| - |
|
151 |
// This flag basically determines whether 'default' labelled image has changed or not
|
| - |
|
152 |
boolean existsNewVersionedDefaultJPGFile = newVersionedDefaultJPGFile.exists();
|
| - |
|
153 |
|
| - |
|
154 |
// If default images are not generated before, or default labelled images are absent, or the global
|
| - |
|
155 |
// image itself got changed, we need to copy these images.
|
| 157 |
if (defaultImageCreationTime == 0 && (!newVersionedDefaultJPGFile.exists() ||
|
156 |
if (defaultImageCreationTime == 0 && (!existsNewVersionedDefaultJPGFile ||
|
| 158 |
globalDefaultJPGFile.lastModified() > Long.parseLong(contentVersion)))
|
157 |
globalDefaultJPGFile.lastModified() > Long.parseLong(contentVersion)))
|
| 159 |
{
|
158 |
{
|
| 160 |
copyFile(globalDefaultJPGFile,
|
159 |
copyFile(globalDefaultJPGFile,
|
| 161 |
new File(websiteMediaDirectory, DEFAULT_JPG));
|
160 |
new File(websiteMediaDirectory, DEFAULT_JPG), true);
|
| 162 |
|
161 |
|
| 163 |
copyFile(globalDefaultJPGFile,
|
162 |
copyFile(globalDefaultJPGFile,
|
| 164 |
newVersionedDefaultJPGFile);
|
163 |
newVersionedDefaultJPGFile, false);
|
| 165 |
|
164 |
|
| 166 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
165 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
| 167 |
new File(websiteMediaDirectory, THUMBNAIL_JPG));
|
166 |
new File(websiteMediaDirectory, THUMBNAIL_JPG), true);
|
| 168 |
|
167 |
|
| 169 |
copyFile(new File(imageDirPath + ICON_JPG),
|
168 |
copyFile(new File(imageDirPath + ICON_JPG),
|
| 170 |
new File(websiteMediaDirectory, ICON_JPG));
|
169 |
new File(websiteMediaDirectory, ICON_JPG), true);
|
| 171 |
|
170 |
|
| 172 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
171 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
| 173 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, THUMBNAIL_JPG,
|
172 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, THUMBNAIL_JPG,
|
| 174 |
String.valueOf(defaultImageCreationTime))));
|
173 |
String.valueOf(defaultImageCreationTime))), false);
|
| 175 |
|
174 |
|
| 176 |
copyFile(new File(imageDirPath + ICON_JPG),
|
175 |
copyFile(new File(imageDirPath + ICON_JPG),
|
| 177 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, ICON_JPG,
|
176 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, ICON_JPG,
|
| 178 |
String.valueOf(defaultImageCreationTime))));
|
177 |
String.valueOf(defaultImageCreationTime))), false);
|
| 179 |
|
178 |
|
| 180 |
// FIXME This should be removed once we are ready with changes in ProductListGenerator.
|
179 |
// FIXME This should be removed once we are ready with changes in ProductListGenerator.
|
| 181 |
copyFile(new File(imageDirPath + ICON_JPG),
|
180 |
copyFile(new File(imageDirPath + ICON_JPG),
|
| 182 |
new File(staticMediaDirectory, ICON_JPG));
|
181 |
new File(staticMediaDirectory, ICON_JPG), true);
|
| 183 |
}
|
182 |
}
|
| 184 |
|
183 |
|
| 185 |
/*
|
184 |
/*
|
| 186 |
* Copying the generated content from db/media to export/media. This
|
185 |
* Copying the generated content from db/media to export/media. This
|
| 187 |
* will also insert a creation timestamp tag in the file names.
|
186 |
* will also insert a creation timestamp tag in the file names.
|
| 188 |
*/
|
187 |
*/
|
| 189 |
for (ExpandedSlide expandedSlide : entity.getExpandedSlides()) {
|
188 |
for (ExpandedSlide expandedSlide : entity.getExpandedSlides()) {
|
| 190 |
FreeformContent freeFormContent = expandedSlide.getFreeformContent();
|
189 |
FreeformContent freeFormContent = expandedSlide
|
| - |
|
190 |
.getFreeformContent();
|
| 191 |
if (freeFormContent != null) {
|
191 |
if (freeFormContent != null) {
|
| 192 |
for (String label : freeFormContent.getImageLabels()) {
|
192 |
for (String label : freeFormContent.getImageLabels()) {
|
| 193 |
final Media image = freeFormContent.getMedias().get(label);
|
193 |
final Media image = freeFormContent.getMedias().get(label);
|
| 194 |
if (isWebsiteImage(image)) {
|
194 |
if (isWebsiteImage(image)) {
|
| - |
|
195 |
// In case, default.jpg is changed, icon.jpg and
|
| - |
|
196 |
// thumbnail.jpg also need to be updated
|
| - |
|
197 |
if (isDefaultImage(image)) {
|
| 195 |
if (image.getCreationTime().getTime() > Long.valueOf(contentVersion)) {
|
198 |
copyFile(new File(image.getLocation()),
|
| 196 |
copyFile(new File(image.getLocation()), new File(websiteMediaDirectory, image.getFileName()));
|
199 |
new File(websiteMediaDirectory, image.getFileName()),
|
| - |
|
200 |
!existsNewVersionedDefaultJPGFile);
|
| 197 |
|
201 |
|
| 198 |
// In case, default.jpg is changed, icon.jpg and thumbnail.jpg
|
- |
|
| 199 |
// also need to be updated
|
- |
|
| 200 |
if (isDefaultImage(image)) {
|
- |
|
| 201 |
/*
|
202 |
/*
|
| 202 |
* Copy the thumbnail and the icon files. This is required so that we
|
203 |
* Copy the thumbnail and the icon files. This is
|
| - |
|
204 |
* required so that we can display the thumbnail on
|
| 203 |
* can display the thumbnail on the cart page and icon on the facebook.
|
205 |
* the cart page and icon on the facebook.
|
| 204 |
*/
|
206 |
*/
|
| 205 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
207 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
| 206 |
new File(websiteMediaDirectory, THUMBNAIL_JPG));
|
208 |
new File(websiteMediaDirectory, THUMBNAIL_JPG),
|
| - |
|
209 |
!existsNewVersionedDefaultJPGFile);
|
| 207 |
|
210 |
|
| 208 |
copyFile(new File(imageDirPath + ICON_JPG),
|
211 |
copyFile(new File(imageDirPath + ICON_JPG),
|
| 209 |
new File(websiteMediaDirectory, ICON_JPG));
|
212 |
new File(websiteMediaDirectory, ICON_JPG),
|
| - |
|
213 |
!existsNewVersionedDefaultJPGFile);
|
| 210 |
}
|
214 |
}
|
| - |
|
215 |
else {
|
| - |
|
216 |
copyFile(new File(image.getLocation()),
|
| - |
|
217 |
new File(websiteMediaDirectory, image.getFileName()),
|
| - |
|
218 |
false);
|
| 211 |
}
|
219 |
}
|
| 212 |
}
|
220 |
}
|
| 213 |
|
221 |
|
| 214 |
// Copying all files with timestamps in static directory
|
222 |
// Copying all files with timestamps in static directory
|
| 215 |
if (image.getCreationTime().getTime() > Long.valueOf(contentVersion)) {
|
223 |
copyFile(new File(image.getLocation()),
|
| 216 |
removeFile(staticMediaDirectory, imagePrefix + HYPHON + image.getFileName().split(ESCAPED_DOT)[0]);
|
- |
|
| 217 |
|
- |
|
| 218 |
copyFile(new File(image.getLocation()), new File(staticMediaDirectory, computeNewFileName(imagePrefix, image.getFileName(),
|
224 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, image.getFileName(),
|
| 219 |
String.valueOf(image.getCreationTime().getTime()))));
|
225 |
String.valueOf(image.getCreationTime().getTime()))), false);
|
| 220 |
|
226 |
|
| 221 |
// If default image is changed icon and thumbnail images are re-copied in static directory
|
227 |
// If default image is changed icon and thumbnail images are
|
| 222 |
if (isDefaultImage(image)) {
|
228 |
// re-copied in static directory
|
| 223 |
removeFile(staticMediaDirectory, imagePrefix + HYPHON + THUMBNAIL_JPG.split(ESCAPED_DOT)[0]);
|
- |
|
| 224 |
removeFile(staticMediaDirectory, imagePrefix + HYPHON + ICON_JPG.split(ESCAPED_DOT)[0]);
|
229 |
if (isDefaultImage(image)) {
|
| 225 |
|
- |
|
| 226 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
230 |
copyFile(new File(imageDirPath + THUMBNAIL_JPG),
|
| 227 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, THUMBNAIL_JPG,
|
231 |
new File(staticMediaDirectory,
|
| 228 |
String.valueOf(image.getCreationTime().getTime()))));
|
232 |
computeNewFileName(imagePrefix, THUMBNAIL_JPG, String.valueOf(image.getCreationTime().getTime()))), false);
|
| 229 |
|
233 |
|
| 230 |
copyFile(new File(imageDirPath + ICON_JPG),
|
234 |
copyFile(new File(imageDirPath + ICON_JPG),
|
| 231 |
new File(staticMediaDirectory, computeNewFileName(imagePrefix, ICON_JPG,
|
235 |
new File(staticMediaDirectory,
|
| 232 |
String.valueOf(image.getCreationTime().getTime()))));
|
236 |
computeNewFileName(imagePrefix, ICON_JPG, String.valueOf(image.getCreationTime().getTime()))), false);
|
| - |
|
237 |
|
| 233 |
|
238 |
// FIXME This should be removed once we are ready with
|
| 234 |
//FIXME This should be removed once we are ready with changes in ProductListGenerator.
|
239 |
// changes in ProductListGenerator.
|
| 235 |
copyFile(new File(imageDirPath + ICON_JPG),
|
240 |
copyFile(new File(imageDirPath + ICON_JPG), new File(
|
| 236 |
new File(staticMediaDirectory, ICON_JPG));
|
241 |
staticMediaDirectory, ICON_JPG), !existsNewVersionedDefaultJPGFile);
|
| 237 |
}
|
- |
|
| 238 |
}
|
242 |
}
|
| 239 |
}
|
243 |
}
|
| 240 |
}
|
244 |
}
|
| 241 |
}
|
245 |
}
|
| 242 |
}
|
246 |
}
|
| 243 |
|
247 |
|
| 244 |
/**
|
248 |
/**
|
| 245 |
* Removes a file in a given directory with a given prefix.
|
- |
|
| 246 |
* It removes only one file.
|
- |
|
| 247 |
*
|
- |
|
| 248 |
* @param staticMediaDirectory the given directory from where file needs to be removed
|
- |
|
| 249 |
* @param fileNamePrefix the given prefix of file name that should be removed
|
- |
|
| 250 |
*/
|
- |
|
| 251 |
private void removeFile(File staticMediaDirectory, final String fileNamePrefix) {
|
- |
|
| 252 |
// Not removing files for now. As we can have files with same names
|
- |
|
| 253 |
// and different labels.
|
- |
|
| 254 |
return;
|
- |
|
| 255 |
// // Deleting the file with same name
|
- |
|
| 256 |
// File[] fileToBeDeleted = staticMediaDirectory.listFiles(new FilenameFilter() {
|
- |
|
| 257 |
//
|
- |
|
| 258 |
// @Override
|
- |
|
| 259 |
// public boolean accept(File dir, String name) {
|
- |
|
| 260 |
// if (name.startsWith(fileNamePrefix)) {
|
- |
|
| 261 |
// return true;
|
- |
|
| 262 |
// }
|
- |
|
| 263 |
//
|
- |
|
| 264 |
// return false;
|
- |
|
| 265 |
// }
|
- |
|
| 266 |
// });
|
- |
|
| 267 |
//
|
- |
|
| 268 |
// // Deleting only one file
|
- |
|
| 269 |
// if (fileToBeDeleted.length != 0) {
|
- |
|
| 270 |
// fileToBeDeleted[0].delete();
|
- |
|
| 271 |
// }
|
- |
|
| 272 |
}
|
- |
|
| 273 |
|
- |
|
| 274 |
/**
|
- |
|
| 275 |
* This method computes new name of a given file. It adds necessary prefix
|
249 |
* This method computes new name of a given file. It adds necessary prefix
|
| 276 |
* and suffix to core file name separated by hyphons keeping extension intact.
|
250 |
* and suffix to core file name separated by hyphons keeping extension intact.
|
| 277 |
* e.g. computeNewFileName("pre", "file.txt", "post") would return "pre-file-post.txt"
|
251 |
* e.g. computeNewFileName("pre", "file.txt", "post") would return "pre-file-post.txt"
|
| 278 |
*
|
252 |
*
|
| 279 |
* @param fileNamePrefix the string to be prefixed
|
253 |
* @param fileNamePrefix the string to be prefixed
|
| Line 310... |
Line 284... |
| 310 |
|
284 |
|
| 311 |
/**
|
285 |
/**
|
| 312 |
* Copies the contents of the source file into the destination file. Creates
|
286 |
* Copies the contents of the source file into the destination file. Creates
|
| 313 |
* the destination file if it doesn't exist already.
|
287 |
* the destination file if it doesn't exist already.
|
| 314 |
*/
|
288 |
*/
|
| 315 |
private void copyFile(File sourceFile, File destFile) throws IOException {
|
289 |
private void copyFile(File sourceFile, File destFile, boolean overwrite) throws IOException {
|
| 316 |
if (!destFile.exists()) {
|
290 |
if (!destFile.exists()) {
|
| 317 |
log.info("File: " + destFile.getName());
|
- |
|
| 318 |
log.info("File: " + destFile.getAbsolutePath());
|
291 |
log.info("Creating file: " + destFile.getAbsolutePath());
|
| 319 |
destFile.createNewFile();
|
292 |
destFile.createNewFile();
|
| 320 |
}
|
293 |
}
|
| - |
|
294 |
else {
|
| - |
|
295 |
// Return in case file should not be overwritten
|
| - |
|
296 |
if (!overwrite) {
|
| - |
|
297 |
log.info("Not overwriting file: " + destFile.getAbsolutePath());
|
| - |
|
298 |
return;
|
| - |
|
299 |
}
|
| - |
|
300 |
|
| - |
|
301 |
log.info("Overwriting file: " + destFile.getAbsolutePath());
|
| - |
|
302 |
}
|
| 321 |
|
303 |
|
| 322 |
FileChannel source = null;
|
304 |
FileChannel source = null;
|
| 323 |
FileChannel destination = null;
|
305 |
FileChannel destination = null;
|
| 324 |
|
306 |
|
| 325 |
try {
|
307 |
try {
|