001
014
015 package com.liferay.portlet.journal.lar;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.json.JSONFactoryUtil;
020 import com.liferay.portal.kernel.json.JSONObject;
021 import com.liferay.portal.kernel.lar.BaseStagedModelDataHandler;
022 import com.liferay.portal.kernel.lar.ExportImportHelperUtil;
023 import com.liferay.portal.kernel.lar.ExportImportPathUtil;
024 import com.liferay.portal.kernel.lar.PortletDataContext;
025 import com.liferay.portal.kernel.lar.StagedModelDataHandlerUtil;
026 import com.liferay.portal.kernel.trash.TrashHandler;
027 import com.liferay.portal.kernel.util.CalendarFactoryUtil;
028 import com.liferay.portal.kernel.util.FileUtil;
029 import com.liferay.portal.kernel.util.LocaleUtil;
030 import com.liferay.portal.kernel.util.LocalizationUtil;
031 import com.liferay.portal.kernel.util.MapUtil;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.Validator;
034 import com.liferay.portal.kernel.workflow.WorkflowConstants;
035 import com.liferay.portal.kernel.xml.Element;
036 import com.liferay.portal.model.Image;
037 import com.liferay.portal.model.User;
038 import com.liferay.portal.service.ImageLocalServiceUtil;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portal.service.UserLocalServiceUtil;
041 import com.liferay.portal.util.PortalUtil;
042 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
043 import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
044 import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
045 import com.liferay.portlet.dynamicdatamapping.service.DDMTemplateLocalServiceUtil;
046 import com.liferay.portlet.journal.model.JournalArticle;
047 import com.liferay.portlet.journal.model.JournalArticleConstants;
048 import com.liferay.portlet.journal.model.JournalArticleImage;
049 import com.liferay.portlet.journal.model.JournalArticleResource;
050 import com.liferay.portlet.journal.model.JournalFolder;
051 import com.liferay.portlet.journal.model.JournalFolderConstants;
052 import com.liferay.portlet.journal.service.JournalArticleImageLocalServiceUtil;
053 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
054 import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
055
056 import java.io.File;
057
058 import java.util.Calendar;
059 import java.util.Date;
060 import java.util.HashMap;
061 import java.util.List;
062 import java.util.Locale;
063 import java.util.Map;
064
065
069 public class JournalArticleStagedModelDataHandler
070 extends BaseStagedModelDataHandler<JournalArticle> {
071
072 public static final String[] CLASS_NAMES = {JournalArticle.class.getName()};
073
074 @Override
075 public void deleteStagedModel(
076 String uuid, long groupId, String className, String extraData)
077 throws PortalException, SystemException {
078
079 JournalArticleResource articleResource =
080 JournalArticleResourceLocalServiceUtil.fetchArticleResource(
081 uuid, groupId);
082
083 if (articleResource == null) {
084 return;
085 }
086
087 JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(
088 extraData);
089
090 if (Validator.isNull(extraData) ||
091 extraDataJSONObject.getBoolean("inTrash")) {
092
093 JournalArticleLocalServiceUtil.deleteArticle(
094 groupId, articleResource.getArticleId(), null);
095 }
096 else {
097 double version = extraDataJSONObject.getDouble("version");
098
099 JournalArticle article = JournalArticleLocalServiceUtil.getArticle(
100 groupId, articleResource.getArticleId(), version);
101
102 JournalArticleLocalServiceUtil.deleteArticle(article);
103 }
104 }
105
106 @Override
107 public String[] getClassNames() {
108 return CLASS_NAMES;
109 }
110
111 @Override
112 public String getDisplayName(JournalArticle article) {
113 return article.getTitleCurrentValue();
114 }
115
116 @Override
117 public int[] getExportableStatuses() {
118 return new int[] {
119 WorkflowConstants.STATUS_APPROVED, WorkflowConstants.STATUS_EXPIRED,
120 WorkflowConstants.STATUS_SCHEDULED
121 };
122 }
123
124 @Override
125 protected boolean countStagedModel(
126 PortletDataContext portletDataContext, JournalArticle article) {
127
128 return !portletDataContext.isModelCounted(
129 JournalArticleResource.class.getName(),
130 article.getResourcePrimKey());
131 }
132
133 @Override
134 protected void doExportStagedModel(
135 PortletDataContext portletDataContext, JournalArticle article)
136 throws Exception {
137
138 Element articleElement = portletDataContext.getExportDataElement(
139 article);
140
141 articleElement.addAttribute(
142 "article-resource-uuid", article.getArticleResourceUuid());
143
144 if (article.getFolderId() !=
145 JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
146
147 StagedModelDataHandlerUtil.exportReferenceStagedModel(
148 portletDataContext, article, article.getFolder(),
149 PortletDataContext.REFERENCE_TYPE_PARENT);
150 }
151
152 if (Validator.isNotNull(article.getStructureId())) {
153 DDMStructure ddmStructure =
154 DDMStructureLocalServiceUtil.getStructure(
155 article.getGroupId(),
156 PortalUtil.getClassNameId(JournalArticle.class),
157 article.getStructureId(), true);
158
159 StagedModelDataHandlerUtil.exportReferenceStagedModel(
160 portletDataContext, article, ddmStructure,
161 PortletDataContext.REFERENCE_TYPE_STRONG);
162 }
163
164 if (Validator.isNotNull(article.getTemplateId())) {
165 DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.getTemplate(
166 article.getGroupId(),
167 PortalUtil.getClassNameId(DDMStructure.class),
168 article.getTemplateId(), true);
169
170 StagedModelDataHandlerUtil.exportReferenceStagedModel(
171 portletDataContext, article, ddmTemplate,
172 PortletDataContext.REFERENCE_TYPE_STRONG);
173 }
174
175 if (article.isSmallImage()) {
176 Image smallImage = ImageLocalServiceUtil.fetchImage(
177 article.getSmallImageId());
178
179 if (Validator.isNotNull(article.getSmallImageURL())) {
180 String smallImageURL =
181 ExportImportHelperUtil.replaceExportContentReferences(
182 portletDataContext, article, articleElement,
183 article.getSmallImageURL().concat(StringPool.SPACE),
184 true);
185
186 article.setSmallImageURL(smallImageURL);
187 }
188 else if (smallImage != null) {
189 String smallImagePath = ExportImportPathUtil.getModelPath(
190 article,
191 smallImage.getImageId() + StringPool.PERIOD +
192 smallImage.getType());
193
194 articleElement.addAttribute("small-image-path", smallImagePath);
195
196 article.setSmallImageType(smallImage.getType());
197
198 portletDataContext.addZipEntry(
199 smallImagePath, smallImage.getTextObj());
200 }
201 }
202
203 List<JournalArticleImage> articleImages =
204 JournalArticleImageLocalServiceUtil.getArticleImages(
205 article.getGroupId(), article.getArticleId(),
206 article.getVersion());
207
208 for (JournalArticleImage articleImage : articleImages) {
209 exportArticleImage(
210 portletDataContext, articleImage, article, articleElement);
211 }
212
213 article.setStatusByUserUuid(article.getStatusByUserUuid());
214
215 String content = ExportImportHelperUtil.replaceExportContentReferences(
216 portletDataContext, article, articleElement, article.getContent(),
217 portletDataContext.getBooleanParameter(
218 JournalPortletDataHandler.NAMESPACE, "referenced-content"));
219
220 article.setContent(content);
221
222 portletDataContext.addClassedModel(
223 articleElement, ExportImportPathUtil.getModelPath(article),
224 article);
225 }
226
227 @Override
228 protected void doImportCompanyStagedModel(
229 PortletDataContext portletDataContext, JournalArticle article)
230 throws Exception {
231
232 JournalArticleResource existingArticleResource =
233 JournalArticleResourceLocalServiceUtil.
234 fetchJournalArticleResourceByUuidAndGroupId(
235 article.getArticleResourceUuid(),
236 portletDataContext.getCompanyGroupId());
237
238 JournalArticle existingArticle =
239 JournalArticleLocalServiceUtil.getLatestArticle(
240 existingArticleResource.getResourcePrimKey(),
241 WorkflowConstants.STATUS_ANY, false);
242
243 Map<String, String> articleArticleIds =
244 (Map<String, String>)portletDataContext.getNewPrimaryKeysMap(
245 JournalArticle.class + ".articleId");
246
247 articleArticleIds.put(
248 article.getArticleId(), existingArticle.getArticleId());
249
250 Map<Long, Long> articleIds =
251 (Map<Long, Long>)portletDataContext.getNewPrimaryKeysMap(
252 JournalArticle.class);
253
254 articleIds.put(article.getId(), existingArticle.getId());
255 }
256
257 @Override
258 protected void doImportStagedModel(
259 PortletDataContext portletDataContext, JournalArticle article)
260 throws Exception {
261
262 prepareLanguagesForImport(article);
263
264 long userId = portletDataContext.getUserId(article.getUserUuid());
265
266 JournalCreationStrategy creationStrategy =
267 JournalCreationStrategyFactory.getInstance();
268
269 long authorId = creationStrategy.getAuthorUserId(
270 portletDataContext, article);
271
272 if (authorId != JournalCreationStrategy.USE_DEFAULT_USER_ID_STRATEGY) {
273 userId = authorId;
274 }
275
276 User user = UserLocalServiceUtil.getUser(userId);
277
278 Map<Long, Long> folderIds =
279 (Map<Long, Long>)portletDataContext.getNewPrimaryKeysMap(
280 JournalFolder.class);
281
282 if (article.getFolderId() !=
283 JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
284
285 Element folderElement = portletDataContext.getReferenceDataElement(
286 article, JournalFolder.class, article.getFolderId());
287
288 StagedModelDataHandlerUtil.importStagedModel(
289 portletDataContext, folderElement);
290 }
291
292 long folderId = MapUtil.getLong(
293 folderIds, article.getFolderId(), article.getFolderId());
294
295 String articleId = article.getArticleId();
296
297 boolean autoArticleId = false;
298
299 if (Validator.isNumber(articleId) ||
300 (JournalArticleLocalServiceUtil.fetchArticle(
301 portletDataContext.getScopeGroupId(), articleId,
302 JournalArticleConstants.VERSION_DEFAULT) != null)) {
303
304 autoArticleId = true;
305 }
306
307 Map<String, String> articleIds =
308 (Map<String, String>)portletDataContext.getNewPrimaryKeysMap(
309 JournalArticle.class + ".articleId");
310
311 String newArticleId = articleIds.get(articleId);
312
313 if (Validator.isNotNull(newArticleId)) {
314
315
316
317
318 articleId = newArticleId;
319 autoArticleId = false;
320 }
321
322 String content = article.getContent();
323
324 Element articleElement =
325 portletDataContext.getImportDataStagedModelElement(article);
326
327 content = ExportImportHelperUtil.replaceImportContentReferences(
328 portletDataContext, articleElement, content, true);
329
330 article.setContent(content);
331
332 String newContent = creationStrategy.getTransformedContent(
333 portletDataContext, article);
334
335 if (newContent != JournalCreationStrategy.ARTICLE_CONTENT_UNCHANGED) {
336 article.setContent(newContent);
337 }
338
339 Date displayDate = article.getDisplayDate();
340
341 int displayDateMonth = 0;
342 int displayDateDay = 0;
343 int displayDateYear = 0;
344 int displayDateHour = 0;
345 int displayDateMinute = 0;
346
347 if (displayDate != null) {
348 Calendar displayCal = CalendarFactoryUtil.getCalendar(
349 user.getTimeZone());
350
351 displayCal.setTime(displayDate);
352
353 displayDateMonth = displayCal.get(Calendar.MONTH);
354 displayDateDay = displayCal.get(Calendar.DATE);
355 displayDateYear = displayCal.get(Calendar.YEAR);
356 displayDateHour = displayCal.get(Calendar.HOUR);
357 displayDateMinute = displayCal.get(Calendar.MINUTE);
358
359 if (displayCal.get(Calendar.AM_PM) == Calendar.PM) {
360 displayDateHour += 12;
361 }
362 }
363
364 Date expirationDate = article.getExpirationDate();
365
366 int expirationDateMonth = 0;
367 int expirationDateDay = 0;
368 int expirationDateYear = 0;
369 int expirationDateHour = 0;
370 int expirationDateMinute = 0;
371 boolean neverExpire = true;
372
373 if (expirationDate != null) {
374 Calendar expirationCal = CalendarFactoryUtil.getCalendar(
375 user.getTimeZone());
376
377 expirationCal.setTime(expirationDate);
378
379 expirationDateMonth = expirationCal.get(Calendar.MONTH);
380 expirationDateDay = expirationCal.get(Calendar.DATE);
381 expirationDateYear = expirationCal.get(Calendar.YEAR);
382 expirationDateHour = expirationCal.get(Calendar.HOUR);
383 expirationDateMinute = expirationCal.get(Calendar.MINUTE);
384 neverExpire = false;
385
386 if (expirationCal.get(Calendar.AM_PM) == Calendar.PM) {
387 expirationDateHour += 12;
388 }
389 }
390
391 Date reviewDate = article.getReviewDate();
392
393 int reviewDateMonth = 0;
394 int reviewDateDay = 0;
395 int reviewDateYear = 0;
396 int reviewDateHour = 0;
397 int reviewDateMinute = 0;
398 boolean neverReview = true;
399
400 if (reviewDate != null) {
401 Calendar reviewCal = CalendarFactoryUtil.getCalendar(
402 user.getTimeZone());
403
404 reviewCal.setTime(reviewDate);
405
406 reviewDateMonth = reviewCal.get(Calendar.MONTH);
407 reviewDateDay = reviewCal.get(Calendar.DATE);
408 reviewDateYear = reviewCal.get(Calendar.YEAR);
409 reviewDateHour = reviewCal.get(Calendar.HOUR);
410 reviewDateMinute = reviewCal.get(Calendar.MINUTE);
411 neverReview = false;
412
413 if (reviewCal.get(Calendar.AM_PM) == Calendar.PM) {
414 reviewDateHour += 12;
415 }
416 }
417
418 String parentDDMStructureKey = StringPool.BLANK;
419
420 long ddmStructureId = 0;
421
422 List<Element> structureElements =
423 portletDataContext.getReferenceDataElements(
424 article, DDMStructure.class);
425
426 if (!structureElements.isEmpty()) {
427 Element structureElement = structureElements.get(0);
428
429 String structurePath = structureElement.attributeValue("path");
430
431 DDMStructure ddmStructure =
432 (DDMStructure)portletDataContext.getZipEntryAsObject(
433 structurePath);
434
435 StagedModelDataHandlerUtil.importReferenceStagedModel(
436 portletDataContext, ddmStructure);
437
438 Map<String, String> ddmStructureKeys =
439 (Map<String, String>)portletDataContext.getNewPrimaryKeysMap(
440 DDMStructure.class + ".ddmStructureKey");
441
442 parentDDMStructureKey = MapUtil.getString(
443 ddmStructureKeys, ddmStructure.getStructureKey(),
444 ddmStructure.getStructureKey());
445 }
446
447 String parentDDMTemplateKey = StringPool.BLANK;
448
449 List<Element> ddmTemplateElements =
450 portletDataContext.getReferenceDataElements(
451 article, DDMTemplate.class);
452
453 if (!ddmTemplateElements.isEmpty()) {
454 Element templateElement = ddmTemplateElements.get(0);
455
456 String ddmTemplatePath = templateElement.attributeValue("path");
457
458 DDMTemplate ddmTemplate =
459 (DDMTemplate)portletDataContext.getZipEntryAsObject(
460 ddmTemplatePath);
461
462 StagedModelDataHandlerUtil.importReferenceStagedModel(
463 portletDataContext, ddmTemplate);
464
465 Map<String, String> ddmTemplateKeys =
466 (Map<String, String>)portletDataContext.getNewPrimaryKeysMap(
467 DDMTemplate.class + ".ddmTemplateKey");
468
469 parentDDMTemplateKey = MapUtil.getString(
470 ddmTemplateKeys, ddmTemplate.getTemplateKey(),
471 ddmTemplate.getTemplateKey());
472 }
473
474 File smallFile = null;
475
476 try {
477 if (article.isSmallImage()) {
478 String smallImagePath = articleElement.attributeValue(
479 "small-image-path");
480
481 if (Validator.isNotNull(article.getSmallImageURL())) {
482 String smallImageURL =
483 ExportImportHelperUtil.replaceImportContentReferences(
484 portletDataContext, articleElement,
485 article.getSmallImageURL(), true);
486
487 article.setSmallImageURL(smallImageURL);
488 }
489 else if (Validator.isNotNull(smallImagePath)) {
490 byte[] bytes = portletDataContext.getZipEntryAsByteArray(
491 smallImagePath);
492
493 if (bytes != null) {
494 smallFile = FileUtil.createTempFile(
495 article.getSmallImageType());
496
497 FileUtil.write(smallFile, bytes);
498 }
499 }
500 }
501
502 Map<String, byte[]> images = new HashMap<String, byte[]>();
503
504 List<Element> imagesElements =
505 portletDataContext.getReferenceDataElements(
506 article, Image.class);
507
508 for (Element imageElement : imagesElements) {
509 String imagePath = imageElement.attributeValue("path");
510
511 String fileName = imageElement.attributeValue("file-name");
512
513 images.put(
514 fileName,
515 portletDataContext.getZipEntryAsByteArray(imagePath));
516 }
517
518 String articleURL = null;
519
520 boolean addGroupPermissions = creationStrategy.addGroupPermissions(
521 portletDataContext, article);
522 boolean addGuestPermissions = creationStrategy.addGuestPermissions(
523 portletDataContext, article);
524
525 ServiceContext serviceContext =
526 portletDataContext.createServiceContext(article);
527
528 serviceContext.setAddGroupPermissions(addGroupPermissions);
529 serviceContext.setAddGuestPermissions(addGuestPermissions);
530
531 if ((article.getStatus() != WorkflowConstants.STATUS_APPROVED) &&
532 (article.getStatus() != WorkflowConstants.STATUS_SCHEDULED)) {
533
534 serviceContext.setWorkflowAction(
535 WorkflowConstants.ACTION_SAVE_DRAFT);
536 }
537
538 JournalArticle importedArticle = null;
539
540 String articleResourceUuid = articleElement.attributeValue(
541 "article-resource-uuid");
542
543 if (portletDataContext.isDataStrategyMirror()) {
544 JournalArticleResource articleResource =
545 JournalArticleResourceLocalServiceUtil.
546 fetchJournalArticleResourceByUuidAndGroupId(
547 articleResourceUuid,
548 portletDataContext.getScopeGroupId());
549
550 serviceContext.setUuid(articleResourceUuid);
551 serviceContext.setAttribute("urlTitle", article.getUrlTitle());
552
553 JournalArticle existingArticle = null;
554
555 if (articleResource != null) {
556 existingArticle =
557 JournalArticleLocalServiceUtil.fetchLatestArticle(
558 articleResource.getResourcePrimKey(),
559 WorkflowConstants.STATUS_ANY, false);
560 }
561
562 if (existingArticle == null) {
563 existingArticle =
564 JournalArticleLocalServiceUtil.fetchArticle(
565 portletDataContext.getScopeGroupId(), newArticleId,
566 article.getVersion());
567 }
568
569 if (existingArticle == null) {
570 importedArticle =
571 JournalArticleLocalServiceUtil.addArticle(
572 userId, portletDataContext.getScopeGroupId(),
573 folderId, article.getClassNameId(), ddmStructureId,
574 articleId, autoArticleId, article.getVersion(),
575 article.getTitleMap(), article.getDescriptionMap(),
576 article.getContent(), article.getType(),
577 parentDDMStructureKey, parentDDMTemplateKey,
578 article.getLayoutUuid(), displayDateMonth,
579 displayDateDay, displayDateYear, displayDateHour,
580 displayDateMinute, expirationDateMonth,
581 expirationDateDay, expirationDateYear,
582 expirationDateHour, expirationDateMinute,
583 neverExpire, reviewDateMonth, reviewDateDay,
584 reviewDateYear, reviewDateHour, reviewDateMinute,
585 neverReview, article.isIndexable(),
586 article.isSmallImage(), article.getSmallImageURL(),
587 smallFile, images, articleURL, serviceContext);
588 }
589 else {
590 importedArticle =
591 JournalArticleLocalServiceUtil.updateArticle(
592 userId, existingArticle.getGroupId(), folderId,
593 existingArticle.getArticleId(),
594 article.getVersion(), article.getTitleMap(),
595 article.getDescriptionMap(), article.getContent(),
596 article.getType(), parentDDMStructureKey,
597 parentDDMTemplateKey, article.getLayoutUuid(),
598 displayDateMonth, displayDateDay, displayDateYear,
599 displayDateHour, displayDateMinute,
600 expirationDateMonth, expirationDateDay,
601 expirationDateYear, expirationDateHour,
602 expirationDateMinute, neverExpire, reviewDateMonth,
603 reviewDateDay, reviewDateYear, reviewDateHour,
604 reviewDateMinute, neverReview,
605 article.isIndexable(), article.isSmallImage(),
606 article.getSmallImageURL(), smallFile, images,
607 articleURL, serviceContext);
608 }
609 }
610 else {
611 importedArticle = JournalArticleLocalServiceUtil.addArticle(
612 userId, portletDataContext.getScopeGroupId(), folderId,
613 article.getClassNameId(), ddmStructureId, articleId,
614 autoArticleId, article.getVersion(), article.getTitleMap(),
615 article.getDescriptionMap(), article.getContent(),
616 article.getType(), parentDDMStructureKey,
617 parentDDMTemplateKey, article.getLayoutUuid(),
618 displayDateMonth, displayDateDay, displayDateYear,
619 displayDateHour, displayDateMinute, expirationDateMonth,
620 expirationDateDay, expirationDateYear, expirationDateHour,
621 expirationDateMinute, neverExpire, reviewDateMonth,
622 reviewDateDay, reviewDateYear, reviewDateHour,
623 reviewDateMinute, neverReview, article.isIndexable(),
624 article.isSmallImage(), article.getSmallImageURL(),
625 smallFile, images, articleURL, serviceContext);
626 }
627
628 portletDataContext.importClassedModel(article, importedArticle);
629
630 if (Validator.isNull(newArticleId)) {
631 articleIds.put(
632 article.getArticleId(), importedArticle.getArticleId());
633 }
634 }
635 finally {
636 if (smallFile != null) {
637 smallFile.delete();
638 }
639 }
640 }
641
642 @Override
643 protected void doRestoreStagedModel(
644 PortletDataContext portletDataContext, JournalArticle article)
645 throws Exception {
646
647 long userId = portletDataContext.getUserId(article.getUserUuid());
648
649 Element articleElement =
650 portletDataContext.getImportDataStagedModelElement(article);
651
652 String articleResourceUuid = articleElement.attributeValue(
653 "article-resource-uuid");
654
655 JournalArticleResource existingArticleResource =
656 JournalArticleResourceLocalServiceUtil.
657 fetchJournalArticleResourceByUuidAndGroupId(
658 articleResourceUuid, portletDataContext.getScopeGroupId());
659
660 if (existingArticleResource == null) {
661 return;
662 }
663
664 JournalArticle existingArticle =
665 JournalArticleLocalServiceUtil.fetchLatestArticle(
666 existingArticleResource.getResourcePrimKey(),
667 WorkflowConstants.STATUS_ANY, false);
668
669 if ((existingArticle == null) || !existingArticle.isInTrash()) {
670 return;
671 }
672
673 TrashHandler trashHandler = existingArticle.getTrashHandler();
674
675 if (trashHandler.isRestorable(existingArticle.getResourcePrimKey())) {
676 trashHandler.restoreTrashEntry(
677 userId, existingArticle.getResourcePrimKey());
678 }
679 }
680
681 protected void exportArticleImage(
682 PortletDataContext portletDataContext,
683 JournalArticleImage articleImage, JournalArticle article,
684 Element articleElement)
685 throws SystemException {
686
687 Image image = ImageLocalServiceUtil.fetchImage(
688 articleImage.getArticleImageId());
689
690 if ((image == null) || (image.getTextObj() == null)) {
691 return;
692 }
693
694 String fileName =
695 image.getImageId() + StringPool.PERIOD + image.getType();
696
697 String articleImagePath = ExportImportPathUtil.getModelPath(
698 article, fileName);
699
700 if (!portletDataContext.isPathNotProcessed(articleImagePath)) {
701 return;
702 }
703
704 Element imageElement = portletDataContext.getExportDataElement(image);
705
706 imageElement.addAttribute("path", articleImagePath);
707
708 if (Validator.isNotNull(fileName)) {
709 imageElement.addAttribute("file-name", fileName);
710 }
711
712 portletDataContext.addZipEntry(articleImagePath, image.getTextObj());
713
714 portletDataContext.addReferenceElement(
715 article, articleElement, image, articleImagePath, false);
716 }
717
718 protected void prepareLanguagesForImport(JournalArticle article)
719 throws PortalException {
720
721 Locale articleDefaultLocale = LocaleUtil.fromLanguageId(
722 article.getDefaultLanguageId());
723
724 Locale[] articleAvailableLocales = LocaleUtil.fromLanguageIds(
725 article.getAvailableLanguageIds());
726
727 Locale defaultImportLocale = LocalizationUtil.getDefaultImportLocale(
728 JournalArticle.class.getName(), article.getPrimaryKey(),
729 articleDefaultLocale, articleAvailableLocales);
730
731 article.prepareLocalizedFieldsForImport(defaultImportLocale);
732 }
733
734 @Override
735 protected boolean validateMissingReference(
736 String uuid, long companyId, long groupId)
737 throws Exception {
738
739 JournalArticle article =
740 JournalArticleLocalServiceUtil.fetchJournalArticleByUuidAndGroupId(
741 uuid, groupId);
742
743 if (article == null) {
744 return false;
745 }
746
747 return true;
748 }
749
750 }