[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
master
tosmers 2018-05-02 17:04:31 +00:00
parent 984a21b93f
commit 289396315b
12 changed files with 313 additions and 18 deletions

View File

@ -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 <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 5/2/18
*/
public class ImageConversion extends AbstractConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.cms.ImageAsset}s from the
* persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link Image}s focusing on keeping all the
* associations in tact.
*/
@Override
public void convertAll() {
ExportLogger.fetching("images");
List<ImageAsset> 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<ImageAsset>
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);
}
}

View File

@ -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);
}

View File

@ -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<Note> getAllObjects() {
List<Note> 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;
}
}

View File

@ -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 <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 5/2/18
*/
public class SideNoteConversion extends AbstractConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.cms.contentassets.Note}s from
* the persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link SideNote}s focusing on keeping all the
* associations in tact.
*/
@Override
public void convertAll() {
ExportLogger.fetching("side notes");
List<Note> 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<Note>
trunkNoteAssets) {
int processed = 0;
for (Note trunkNoteAsset : trunkNoteAssets) {
// create side note
SideNote sideNote = new SideNote(trunkNoteAsset);
processed++;
}
ExportLogger.created("side notes", processed);
}
}

View File

@ -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<ImageAsset> getAllObjects() {
List<ImageAsset> 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;
}
}

View File

@ -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());
}
}
}

View File

@ -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();

View File

@ -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 <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
@ -36,9 +38,69 @@ public class LegalMetadata extends Asset implements Portable {
private String creator;
private List<String> contributors;
public LegalMetadata() {
super(null);
/**
* Constructor for ng-object.
*
* Old trunk system did not keep information about an assets legal
* metadata, therefore it needs to be created now for all ng-objects
* assets.
*
* @param assetName The name of the asset this legal metadata is created
* for
*/
public LegalMetadata(final String assetName) {
super(assetName + "-LegalMetadata");
//this.rightsHolder
this.rights = new LocalizedString();
//this.publisher
//this.creator
this.contributors = new ArrayList<>();
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<String> getContributors() {
return contributors;
}
public void setContributors(final List<String> contributors) {
this.contributors = contributors;
}
}

View File

@ -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}

View File

@ -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,

View File

@ -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
*/

View File

@ -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);
}