Skip to content
This repository has been archived by the owner on Nov 20, 2021. It is now read-only.

Commit

Permalink
LPS-55420 Move common logic to method
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Garcia authored and brianchandotcom committed May 18, 2015
1 parent d6defbe commit 6349a13
Showing 1 changed file with 46 additions and 81 deletions.
Expand Up @@ -443,23 +443,7 @@ public JournalArticle addArticle(
classPK, content, serviceContext);
}
else {
DDMStructure ddmStructure = ddmStructureLocalService.getStructure(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(JournalArticle.class),
ddmStructureKey, true);

ddmStorageLinkLocalService.addStorageLink(
ddmStructure.getClassNameId(), id,
ddmStructure.getStructureId(), serviceContext);

DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(DDMStructure.class),
ddmTemplateKey, true);

ddmTemplateLinkLocalService.addTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class), id,
ddmTemplate.getTemplateId());
updateDDMLinks(groupId, id, ddmStructureKey, ddmTemplateKey, true);
}

// Message boards
Expand Down Expand Up @@ -893,24 +877,10 @@ public JournalArticle copyArticle(

// Dynamic data mapping

DDMStructure ddmStructure = ddmStructureLocalService.getStructure(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(JournalArticle.class),
oldArticle.getDDMStructureKey(), true);

ddmStorageLinkLocalService.addStorageLink(
ddmStructure.getClassNameId(), id, ddmStructure.getStructureId(),
new ServiceContext());

DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(DDMStructure.class),
updateDDMLinks(
groupId, id, oldArticle.getDDMStructureKey(),
oldArticle.getDDMTemplateKey(), true);

ddmTemplateLinkLocalService.addTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class), id,
ddmTemplate.getTemplateId());

return newArticle;
}

Expand Down Expand Up @@ -5314,38 +5284,9 @@ else if (!expired) {
article.getClassPK(), content, serviceContext);
}
else {
DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(DDMStructure.class),
ddmTemplateKey, true);

DDMStructure ddmStructure = ddmStructureLocalService.getStructure(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(JournalArticle.class),
ddmStructureKey, true);

if (addNewVersion) {
ddmStorageLinkLocalService.addStorageLink(
ddmStructure.getClassNameId(), article.getId(),
ddmStructure.getStructureId(), serviceContext);

ddmTemplateLinkLocalService.addTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class),
article.getId(), ddmTemplate.getTemplateId());
}
else {
DDMStorageLink ddmStorageLink =
ddmStorageLinkLocalService.getClassStorageLink(
article.getId());

ddmStorageLink.setStructureId(ddmStructure.getStructureId());

ddmStorageLinkLocalService.updateDDMStorageLink(ddmStorageLink);

ddmTemplateLinkLocalService.updateTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class),
article.getId(), ddmTemplate.getTemplateId());
}
updateDDMLinks(
groupId, article.getId(), ddmStructureKey, ddmTemplateKey,
addNewVersion);
}

// Small image
Expand Down Expand Up @@ -5557,23 +5498,9 @@ public JournalArticle updateArticleTranslation(

// Dynamic data mapping

DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(DDMStructure.class),
updateDDMLinks(
groupId, id, oldArticle.getDDMStructureKey(),
oldArticle.getDDMTemplateKey(), true);

DDMStructure ddmStructure = ddmStructureLocalService.getStructure(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(JournalArticle.class),
oldArticle.getDDMStructureKey(), true);

ddmStorageLinkLocalService.addStorageLink(
ddmStructure.getClassNameId(), article.getId(),
ddmStructure.getStructureId(), serviceContext);

ddmTemplateLinkLocalService.addTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class),
article.getId(), ddmTemplate.getTemplateId());
}
else {
article = oldArticle;
Expand Down Expand Up @@ -7469,6 +7396,44 @@ protected void updateDDMFormFieldPredefinedValue(
}
}

protected void updateDDMLinks(
long groupId, long id, String ddmStructureKey,
String ddmTemplateKey, boolean incrementVersion)
throws PortalException {

DDMStructure ddmStructure = ddmStructureLocalService.getStructure(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(JournalArticle.class),
ddmStructureKey, true);

DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(
PortalUtil.getSiteGroupId(groupId),
classNameLocalService.getClassNameId(DDMStructure.class),
ddmTemplateKey, true);

if (incrementVersion) {
ddmStorageLinkLocalService.addStorageLink(
ddmStructure.getClassNameId(), id,
ddmStructure.getStructureId(), new ServiceContext());

ddmTemplateLinkLocalService.addTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class), id,
ddmTemplate.getTemplateId());
}
else {
DDMStorageLink ddmStorageLink =
ddmStorageLinkLocalService.getClassStorageLink(id);

ddmStorageLink.setStructureId(ddmStructure.getStructureId());

ddmStorageLinkLocalService.updateDDMStorageLink(ddmStorageLink);

ddmTemplateLinkLocalService.updateTemplateLink(
classNameLocalService.getClassNameId(JournalArticle.class), id,
ddmTemplate.getTemplateId());
}
}

protected void updateDDMStructurePredefinedValues(
long ddmStructureId, String content, ServiceContext serviceContext) {

Expand Down

0 comments on commit 6349a13

Please sign in to comment.