From 289396315bc1848a7317305767b2fa368aae50ba Mon Sep 17 00:00:00 2001 From: tosmers Date: Wed, 2 May 2018 17:04:31 +0000 Subject: [PATCH] [TRUNK][FEATURE] - adds conversions for ContentAssets FileAsset, Image and LegalMetadata, SideNote git-svn-id: https://svn.libreccm.org/ccm/trunk@5397 8810af33-2d31-482b-a856-94f89814c4df --- .../conversion/assets/ImageConversion.java | 76 +++++++++++++++++++ .../cms/portation/modules/assets/Image.java | 2 +- .../com/arsdigita/cms/contentassets/Note.java | 30 ++++++++ .../conversion/assets/SideNoteConversion.java | 70 +++++++++++++++++ ccm-cms/src/com/arsdigita/cms/ImageAsset.java | 30 +++++++- .../portation/conversion/CmsConverter.java | 19 ++++- .../portation/modules/assets/BinaryAsset.java | 4 +- .../modules/assets/LegalMetadata.java | 66 +++++++++++++++- .../modules/contentsection/Asset.java | 20 ++++- .../modules/contentsection/Folder.java | 10 +-- .../modules/core/categorization/Category.java | 2 +- .../modules/core/core/CcmObject.java | 2 +- 12 files changed, 313 insertions(+), 18 deletions(-) create mode 100644 ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/conversion/assets/ImageConversion.java create mode 100644 ccm-cms-assets-notes/src/com/arsdigita/cms/portation/conversion/assets/SideNoteConversion.java diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/conversion/assets/ImageConversion.java b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/conversion/assets/ImageConversion.java new file mode 100644 index 000000000..332f45906 --- /dev/null +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/conversion/assets/ImageConversion.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2015 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.portation.conversion.assets; + +import com.arsdigita.cms.ImageAsset; +import com.arsdigita.cms.portation.modules.assets.Image; +import com.arsdigita.cms.portation.modules.assets.LegalMetadata; +import com.arsdigita.portation.AbstractConversion; +import com.arsdigita.portation.cmd.ExportLogger; + +import java.util.List; + +/** + * @author trunkImageAssets = ImageAsset.getAllObjects(); + + ExportLogger.converting("images"); + createImagesAndSetAssociations(trunkImageAssets); + + ExportLogger.newLine(); + } + + /** + * Creates the equivalent ng-class of the {@code FileAsset} and restores the + * associations to other classes. + * + * @param trunkImageAssets List of all {@link com.arsdigita.cms.ImageAsset}s + * from this old trunk-system. + */ + private void createImagesAndSetAssociations(final List + trunkImageAssets) { + int processed = 0; + for (ImageAsset trunkImageAsset : trunkImageAssets) { + + // create image + Image image = new Image(trunkImageAsset); + + // create legalMetadata + LegalMetadata legalMetadata = new LegalMetadata( + trunkImageAsset.getName()); + image.setLegalMetadata(legalMetadata); + + processed++; + } + ExportLogger.created("images", processed); + ExportLogger.created("legal metadatas", processed); + } +} diff --git a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/modules/assets/Image.java b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/modules/assets/Image.java index 38eb1a4f3..b167d3b5c 100644 --- a/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/modules/assets/Image.java +++ b/ccm-cms-assets-imagestep/src/com/arsdigita/cms/portation/modules/assets/Image.java @@ -44,7 +44,7 @@ public class Image extends BinaryAsset implements Portable { this.width = trunkImage.getWidth().longValue(); this.height = trunkImage.getHeight().longValue(); - //this.legalMetaData + //this.legalMetadata NgCmsImageCollection.images.put(this.getObjectId(), this); } diff --git a/ccm-cms-assets-notes/src/com/arsdigita/cms/contentassets/Note.java b/ccm-cms-assets-notes/src/com/arsdigita/cms/contentassets/Note.java index 3b793a584..9e351543d 100755 --- a/ccm-cms-assets-notes/src/com/arsdigita/cms/contentassets/Note.java +++ b/ccm-cms-assets-notes/src/com/arsdigita/cms/contentassets/Note.java @@ -15,11 +15,15 @@ */ package com.arsdigita.cms.contentassets; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import com.arsdigita.auditing.AuditingObserver; import com.arsdigita.auditing.BasicAuditTrail; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ImageAsset; +import com.arsdigita.domain.DomainCollection; import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectInstantiator; @@ -28,6 +32,7 @@ import com.arsdigita.kernel.User; import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.Session; import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.Assert; @@ -221,4 +226,29 @@ public class Note extends ACSObject { } } + /** + * Retrieves all objects of this type stored in the database. Very + * necessary for exporting all entities of the current work environment. + * + * @return List of all objects + */ + public static List getAllObjects() { + List objectList = new ArrayList<>(); + + final Session session = SessionManager.getSession(); + DomainCollection collection = new DomainCollection(session.retrieve( + Note.BASE_DATA_OBJECT_TYPE)); + + while (collection.next()) { + Note object = (Note) collection + .getDomainObject(); + if (object != null) { + objectList.add(object); + } + } + + collection.close(); + return objectList; + } + } diff --git a/ccm-cms-assets-notes/src/com/arsdigita/cms/portation/conversion/assets/SideNoteConversion.java b/ccm-cms-assets-notes/src/com/arsdigita/cms/portation/conversion/assets/SideNoteConversion.java new file mode 100644 index 000000000..05b7c8f2c --- /dev/null +++ b/ccm-cms-assets-notes/src/com/arsdigita/cms/portation/conversion/assets/SideNoteConversion.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.portation.conversion.assets; + +import com.arsdigita.cms.contentassets.Note; +import com.arsdigita.cms.portation.modules.assets.SideNote; +import com.arsdigita.portation.AbstractConversion; +import com.arsdigita.portation.cmd.ExportLogger; + +import java.util.List; + +/** + * @author trunkNoteAssets = Note.getAllObjects(); + + ExportLogger.converting("side notes"); + createSideNotesAndSetAssociations(trunkNoteAssets); + + ExportLogger.newLine(); + } + + /** + * Creates the equivalent ng-class of the {@code SideNote} and restores the + * associations to other classes. + * + * @param trunkNoteAssets List of all + * {@link com.arsdigita.cms.contentassets.Note}s + * from this old trunk-system. + */ + private void createSideNotesAndSetAssociations(final List + trunkNoteAssets) { + int processed = 0; + for (Note trunkNoteAsset : trunkNoteAssets) { + + // create side note + SideNote sideNote = new SideNote(trunkNoteAsset); + + processed++; + } + ExportLogger.created("side notes", processed); + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/ImageAsset.java b/ccm-cms/src/com/arsdigita/cms/ImageAsset.java index 4e517b6a0..b4090df02 100755 --- a/ccm-cms/src/com/arsdigita/cms/ImageAsset.java +++ b/ccm-cms/src/com/arsdigita/cms/ImageAsset.java @@ -19,12 +19,14 @@ package com.arsdigita.cms; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainCollection; import com.arsdigita.mimetypes.ImageMimeType; import com.arsdigita.mimetypes.MimeType; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.Filter; import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.Session; import com.arsdigita.persistence.SessionManager; import com.arsdigita.versioning.VersionedACSObject; import java.awt.image.BufferedImage; @@ -35,6 +37,8 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; import javax.imageio.ImageIO; import org.apache.log4j.Logger; @@ -130,7 +134,7 @@ public class ImageAsset extends BinaryAsset { * @return the Blob content */ @Override - protected byte[] getContent() { + public byte[] getContent() { return (byte[]) get(CONTENT); } @@ -327,4 +331,28 @@ public class ImageAsset extends BinaryAsset { setHeight(new BigDecimal(image.getHeight())); } + /** + * Retrieves all objects of this type stored in the database. Very + * necessary for exporting all entities of the current work environment. + * + * @return List of all objects + */ + public static List getAllObjects() { + List objectList = new ArrayList<>(); + + final Session session = SessionManager.getSession(); + DomainCollection collection = new DomainCollection(session.retrieve( + ImageAsset.BASE_DATA_OBJECT_TYPE)); + + while (collection.next()) { + ImageAsset object = (ImageAsset) collection + .getDomainObject(); + if (object != null) { + objectList.add(object); + } + } + + collection.close(); + return objectList; + } } diff --git a/ccm-cms/src/com/arsdigita/cms/portation/conversion/CmsConverter.java b/ccm-cms/src/com/arsdigita/cms/portation/conversion/CmsConverter.java index 53e41b671..9558c3412 100644 --- a/ccm-cms/src/com/arsdigita/cms/portation/conversion/CmsConverter.java +++ b/ccm-cms/src/com/arsdigita/cms/portation/conversion/CmsConverter.java @@ -62,38 +62,36 @@ public class CmsConverter extends AbstractConverter { LifecycleConversion.getInstance().convertAll(); PhaseConversion.getInstance().convertAll(); + FolderConversion.getInstance().convertAll(); ContentTypeConversion.getInstance().convertAll(); ContentSectionConversion.getInstance().convertAll(); + final Class c = Class.forName("com.arsdigita.cms.portation" + ".conversion.contenttypes.ArticleConversion"); if (c != null) { Method startConversionToNg = c.getDeclaredMethod("convertAll"); startConversionToNg.invoke(c.newInstance()); } - final Class c1 = Class.forName("com.arsdigita.cms.portation" + ".conversion.contenttypes.EventConversion"); if (c1 != null) { Method startConversionToNg = c1.getDeclaredMethod("convertAll"); startConversionToNg.invoke(c1.newInstance()); } - final Class c2 = Class.forName("com.arsdigita.cms.portation" + ".conversion.contenttypes.MultiPartArticleSectionConversion"); if (c2 != null) { Method startConversionToNg = c2.getDeclaredMethod("convertAll"); startConversionToNg.invoke(c2.newInstance()); } - final Class c3 = Class.forName("com.arsdigita.cms.portation" + ".conversion.contenttypes.MultiPartArticleConversion"); if (c3 != null) { Method startConversionToNg = c3.getDeclaredMethod("convertAll"); startConversionToNg.invoke(c3.newInstance()); } - final Class c4 = Class.forName("com.arsdigita.cms.portation" + ".conversion.contenttypes.NewsConversion"); if (c4 != null) { @@ -101,11 +99,24 @@ public class CmsConverter extends AbstractConverter { startConversionToNg.invoke(c4.newInstance()); } + final Class c5 = Class.forName("com.arsdigita.cms.portation" + ".conversion.assets.FileAssetConversion"); if (c5 != null) { Method startConversionToNg = c5.getDeclaredMethod("convertAll"); startConversionToNg.invoke(c5.newInstance()); } + final Class c6 = Class.forName("com.arsdigita.cms.portation" + + ".conversion.assets.ImageConversion"); + if (c6 != null) { + Method startConversionToNg = c6.getDeclaredMethod("convertAll"); + startConversionToNg.invoke(c6.newInstance()); + } + final Class c7 = Class.forName("com.arsdigita.cms.portation" + + ".conversion.assets.SideNoteConversion"); + if (c7 != null) { + Method startConversionToNg = c7.getDeclaredMethod("convertAll"); + startConversionToNg.invoke(c7.newInstance()); + } } } diff --git a/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/BinaryAsset.java b/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/BinaryAsset.java index 08a105c39..ef2d41631 100644 --- a/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/BinaryAsset.java +++ b/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/BinaryAsset.java @@ -46,7 +46,9 @@ public class BinaryAsset extends Asset { super(trunkBinaryAsset); this.description = new LocalizedString(); - final Locale language = new Locale(trunkBinaryAsset.getLanguage()); + final Locale language = trunkBinaryAsset.getLanguage() != null + ? new Locale(trunkBinaryAsset.getLanguage()) + : Locale.getDefault(); this.description.addValue(language, trunkBinaryAsset.getDescription()); this.fileName = trunkBinaryAsset.getName(); diff --git a/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/LegalMetadata.java b/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/LegalMetadata.java index 72f543854..5d7a664c3 100644 --- a/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/LegalMetadata.java +++ b/ccm-cms/src/com/arsdigita/cms/portation/modules/assets/LegalMetadata.java @@ -23,7 +23,9 @@ import com.arsdigita.cms.portation.modules.contentsection.Asset; import com.arsdigita.portation.Portable; import com.arsdigita.portation.modules.core.l10n.LocalizedString; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; /** * @author (); NgCmsCollection.legalMetadatas.put(this.getObjectId(), this); } + + public String getRightsHolder() { + return rightsHolder; + } + + public void setRightsHolder(final String rightsHolder) { + this.rightsHolder = rightsHolder; + } + + public LocalizedString getRights() { + return rights; + } + + public void setRights(final LocalizedString rights) { + this.rights = rights; + } + + public void addRights(final Locale language, final String right) { + this.rights.addValue(language, right); + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(final String publisher) { + this.publisher = publisher; + } + + public String getCreator() { + return creator; + } + + public void setCreator(final String creator) { + this.creator = creator; + } + + public List getContributors() { + return contributors; + } + + public void setContributors(final List contributors) { + this.contributors = contributors; + } } diff --git a/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Asset.java b/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Asset.java index 24f095a00..b1c9b4333 100644 --- a/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Asset.java +++ b/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Asset.java @@ -19,6 +19,7 @@ package com.arsdigita.cms.portation.modules.contentsection; import com.arsdigita.cms.portation.conversion.NgCmsCollection; +import com.arsdigita.kernel.ACSObject; import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.l10n.LocalizedString; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -52,14 +53,29 @@ public class Asset extends CcmObject { this.itemAttachments = new ArrayList<>(); this.title = new LocalizedString(); - final Locale language = new Locale(trunkAsset.getLanguage()); + final Locale language = trunkAsset.getLanguage() != null + ? new Locale(trunkAsset.getLanguage()) + : Locale.getDefault(); this.title.addValue(language, trunkAsset.getName()); NgCmsCollection.assets.put(this.getObjectId(), this); } /** - * Specific constructor for subclass SideNews. + * Specific constructor for subclass of Asset: LegalMetadata + * + * Generates new id. + * + * @param name the display name of this asset + */ + public Asset(final String name) { + this(ACSObject.generateID(), name); + } + + /** + * Specific constructor for subclass of Asset: SideNote. + * + * Uses given id. * * @param objectId The id of this asset * @param displayName The display name as the {@link CcmObject} diff --git a/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Folder.java b/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Folder.java index 2e57f0f9f..17887c77f 100644 --- a/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Folder.java +++ b/ccm-cms/src/com/arsdigita/cms/portation/modules/contentsection/Folder.java @@ -73,11 +73,11 @@ public class Folder extends Category { public Folder(final FolderType folderType, final String sectionName) { super(new CategoryInformation( ACSObject.generateID(), - folderType + "-" + sectionName, - folderType + "-" + sectionName, - folderType + "-" + sectionName, - "This is the " + folderType + " for the content " - + "section: " + sectionName, + sectionName + "-" + folderType, + sectionName + "-" + folderType, + sectionName + "-" + folderType, + String.format("This is the %s for the content section: %s.", + folderType, sectionName), true, true, false, diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java index 8740e03ca..033ae7378 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java @@ -114,7 +114,7 @@ public class Category extends CcmObject implements Portable { } /** - * Specific constructor for subclasses of category e.g. Folder + * Specific constructor for subclasses of Category e.g. Folder * * @param categoryInformation the trunk object */ diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java b/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java index 0c4c67cd0..d7142592f 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java @@ -76,7 +76,7 @@ public class CcmObject { NgCoreCollection.ccmObjects.put(this.objectId, this); } - // specific constructor for ldn-terms' domain + // specific constructor for ldn-terms' Domain and LegalMetadata public CcmObject(final String displayName) { this(ACSObject.generateID(), displayName); }