Exporters for FileAttachments
git-svn-id: https://svn.libreccm.org/ccm/trunk@5720 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
000d490746
commit
84502c8dda
|
|
@ -25,13 +25,20 @@ import com.arsdigita.search.MetadataProviderRegistry;
|
||||||
import com.arsdigita.util.StringUtils;
|
import com.arsdigita.util.StringUtils;
|
||||||
import com.arsdigita.xml.XML;
|
import com.arsdigita.xml.XML;
|
||||||
|
|
||||||
|
import org.libreccm.export.ExportManager;
|
||||||
|
import org.librecms.assets.FileAssetsExporter;
|
||||||
|
import org.librecms.assets.FileAttachmentListsExporter;
|
||||||
|
import org.librecms.assets.FileAttachmentsExporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializer
|
* Initializer
|
||||||
*
|
*
|
||||||
* @author Rafael H. Schloming <rhs@mit.edu>
|
* @author Rafael H. Schloming <rhs@mit.edu>
|
||||||
* @version $Revision: 1.1 $ $Date: 2004/12/15 15:37:51 $
|
* @version $Revision: 1.1 $ $Date: 2004/12/15 15:37:51 $
|
||||||
* @version $Id: FileAttachmentInitializer.java 1262 2006-07-17 08:15:45Z cgyg9330 $
|
* @version $Id: FileAttachmentInitializer.java 1262 2006-07-17 08:15:45Z
|
||||||
**/
|
* cgyg9330 $
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class FileAttachmentInitializer extends ContentAssetInitializer {
|
public class FileAttachmentInitializer extends ContentAssetInitializer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,9 +51,9 @@ public class FileAttachmentInitializer extends ContentAssetInitializer {
|
||||||
/**
|
/**
|
||||||
* Initializes content asset by parsing traversal xml file and registering
|
* Initializes content asset by parsing traversal xml file and registering
|
||||||
* the specified steps in a transient storage which may be modified during
|
* the specified steps in a transient storage which may be modified during
|
||||||
* operation and has to be re-initialized each system startup).
|
* operation and has to be re-initialized each system startup). Essential
|
||||||
* Essential part of initializing the systems domain coupling machinery.
|
* part of initializing the systems domain coupling machinery.
|
||||||
|
*
|
||||||
* @param evt
|
* @param evt
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -75,24 +82,31 @@ public class FileAttachmentInitializer extends ContentAssetInitializer {
|
||||||
* chris.gilbert@westsussex.gov.uk
|
* chris.gilbert@westsussex.gov.uk
|
||||||
*/
|
*/
|
||||||
MetadataProviderRegistry.registerAdapter(
|
MetadataProviderRegistry.registerAdapter(
|
||||||
FileAttachment.BASE_DATA_OBJECT_TYPE,
|
FileAttachment.BASE_DATA_OBJECT_TYPE,
|
||||||
new FileAttachmentMetadataProvider());
|
new FileAttachmentMetadataProvider());
|
||||||
|
|
||||||
XML.parseResource(
|
XML.parseResource(
|
||||||
"/WEB-INF/traversal-adapters/com/arsdigita/cms/contentassets/"
|
"/WEB-INF/traversal-adapters/com/arsdigita/cms/contentassets/"
|
||||||
+ "FileAttachment-search.xml",
|
+ "FileAttachment-search.xml",
|
||||||
new TraversalHandler());
|
new TraversalHandler());
|
||||||
|
|
||||||
final String traversal = getTraversalXML();
|
final String traversal = getTraversalXML();
|
||||||
if(!StringUtils.emptyString(traversal)) {
|
if (!StringUtils.emptyString(traversal)) {
|
||||||
XML.parseResource(traversal, new TraversalHandler());
|
XML.parseResource(traversal, new TraversalHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExportManager.getInstance().registerExporter(new FileAssetsExporter());
|
||||||
|
ExportManager
|
||||||
|
.getInstance()
|
||||||
|
.registerExporter(new FileAttachmentListsExporter());
|
||||||
|
ExportManager
|
||||||
|
.getInstance()
|
||||||
|
.registerExporter(new FileAttachmentsExporter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base type against which the asset is defined,
|
* The base type against which the asset is defined, typically
|
||||||
* typically com.arsdigita.cms.ContentPage
|
* com.arsdigita.cms.ContentPage
|
||||||
*/
|
*/
|
||||||
public String getBaseType() {
|
public String getBaseType() {
|
||||||
return ContentPage.BASE_DATA_OBJECT_TYPE;
|
return ContentPage.BASE_DATA_OBJECT_TYPE;
|
||||||
|
|
@ -104,12 +118,12 @@ public class FileAttachmentInitializer extends ContentAssetInitializer {
|
||||||
*/
|
*/
|
||||||
public String getTraversalXML() {
|
public String getTraversalXML() {
|
||||||
return "/WEB-INF/traversal-adapters/com/arsdigita/"
|
return "/WEB-INF/traversal-adapters/com/arsdigita/"
|
||||||
+ "cms/contentassets/FileAttachment.xml";
|
+ "cms/contentassets/FileAttachment.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the association between the item
|
* The name of the association between the item and the asset, eg
|
||||||
* and the asset, eg 'fileAttachments'.
|
* 'fileAttachments'.
|
||||||
*/
|
*/
|
||||||
public String getProperty() {
|
public String getProperty() {
|
||||||
return "fileAttachments";
|
return "fileAttachments";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.librecms.contentsection.AbstractBinaryAssetsExporter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class FileAssetsExporter
|
||||||
|
extends AbstractBinaryAssetsExporter<FileAttachment> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void exportBinaryAssetProperties(
|
||||||
|
final FileAttachment asset,
|
||||||
|
final JsonGenerator jsonGenerator)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
// Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<FileAttachment> exportsType() {
|
||||||
|
|
||||||
|
return FileAttachment.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String exportsBaseDataObjectType() {
|
||||||
|
|
||||||
|
return FileAttachment.BASE_DATA_OBJECT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertsToType() {
|
||||||
|
|
||||||
|
return "org.librecms.assets.FileAsset";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
|
||||||
|
import org.librecms.contentsection.AbstractAttachmentListsExporter;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class FileAttachmentListsExporter
|
||||||
|
extends AbstractAttachmentListsExporter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getListName() {
|
||||||
|
return "files";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean hasList(final ContentItem item) {
|
||||||
|
|
||||||
|
final DataCollection attachments = FileAttachment.getAttachments(item);
|
||||||
|
|
||||||
|
final boolean result = attachments.next();
|
||||||
|
attachments.close();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.contentassets.FileAttachment;
|
||||||
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
import com.arsdigita.persistence.DataObject;
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
import com.arsdigita.web.WebConfig;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonEncoding;
|
||||||
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.libreccm.export.AbstractDomainObjectsExporter;
|
||||||
|
import org.libreccm.export.IdSequence;
|
||||||
|
import org.librecms.contentsection.AbstractAttachmentListsExporter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class FileAttachmentsExporter
|
||||||
|
extends AbstractDomainObjectsExporter<ContentItem> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<ContentItem> exportsType() {
|
||||||
|
return ContentItem.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String exportsBaseDataObjectType() {
|
||||||
|
return ContentItem.BASE_DATA_OBJECT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertsToType() {
|
||||||
|
return "org.librecms.contentsection.ItemAttachment";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean includeSubTypes() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> exportDomainObject(
|
||||||
|
final ContentItem item, final Path targetDir) {
|
||||||
|
|
||||||
|
final String listUuid = AbstractAttachmentListsExporter
|
||||||
|
.generateListUuid(item, "files");
|
||||||
|
|
||||||
|
final List<String> attachmentUuids = new ArrayList<>();
|
||||||
|
|
||||||
|
final DataCollection fileAttachments = FileAttachment
|
||||||
|
.getAttachments(item);
|
||||||
|
|
||||||
|
long sortKey = 0;
|
||||||
|
while (fileAttachments.next()) {
|
||||||
|
|
||||||
|
sortKey++;
|
||||||
|
final String uuid = exportFileAttachment(fileAttachments
|
||||||
|
.getDataObject(),
|
||||||
|
listUuid,
|
||||||
|
sortKey,
|
||||||
|
targetDir);
|
||||||
|
attachmentUuids.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachmentUuids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String exportFileAttachment(final DataObject dataObj,
|
||||||
|
final String listUuid,
|
||||||
|
final long sortKey,
|
||||||
|
final Path targetDir) {
|
||||||
|
|
||||||
|
final FileAttachment fileAttachment = new FileAttachment(dataObj);
|
||||||
|
final String fileAssetUuid = generateUuid(fileAttachment);
|
||||||
|
|
||||||
|
final byte[] uuidSource = String.format(
|
||||||
|
"%s/files/%s",
|
||||||
|
WebConfig.getInstanceOf().getSiteName(),
|
||||||
|
fileAttachment.getOID().toString())
|
||||||
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
|
final String uuid = UUID.nameUUIDFromBytes(uuidSource).toString();
|
||||||
|
|
||||||
|
final Path targetFilePath = generateTargetFilePath(targetDir, uuid);
|
||||||
|
final File targetFile = targetFilePath.toFile();
|
||||||
|
|
||||||
|
final JsonFactory jsonFactory = new JsonFactory();
|
||||||
|
try (JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
.createGenerator(targetFile, JsonEncoding.UTF8)) {
|
||||||
|
|
||||||
|
jsonGenerator.writeStartObject();
|
||||||
|
|
||||||
|
jsonGenerator.writeNumberField("attachmentId",
|
||||||
|
IdSequence.getInstance().nextId());
|
||||||
|
jsonGenerator.writeStringField("uuid", uuid);
|
||||||
|
|
||||||
|
jsonGenerator.writeStringField("attachmentList", listUuid);
|
||||||
|
jsonGenerator.writeStringField("asset", fileAssetUuid);
|
||||||
|
|
||||||
|
jsonGenerator.writeNumberField("sortKey", sortKey);
|
||||||
|
|
||||||
|
jsonGenerator.writeEndObject();
|
||||||
|
|
||||||
|
return uuid;
|
||||||
|
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new UncheckedWrapperException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -85,6 +85,7 @@ import com.arsdigita.xml.XML;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.libreccm.export.ExportManager;
|
import org.libreccm.export.ExportManager;
|
||||||
|
import org.librecms.contentsection.AbstractAttachmentListsExporter;
|
||||||
import org.librecms.workflow.CmsTasksExporter;
|
import org.librecms.workflow.CmsTasksExporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -250,6 +251,9 @@ public class Initializer extends CompoundInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
ExportManager.getInstance().registerExporter(new CmsTasksExporter());
|
ExportManager.getInstance().registerExporter(new CmsTasksExporter());
|
||||||
|
// ExportManager
|
||||||
|
// .getInstance()
|
||||||
|
// .registerExporter(new AbstractAttachmentListsExporter());
|
||||||
|
|
||||||
s_log.debug("CMS.Initializer.init(DomainInitEvent) completed");
|
s_log.debug("CMS.Initializer.init(DomainInitEvent) completed");
|
||||||
} // END init(DomainInitEvent e)
|
} // END init(DomainInitEvent e)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,235 @@
|
||||||
|
package org.librecms.contentsection;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
import com.arsdigita.web.WebConfig;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonEncoding;
|
||||||
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.libreccm.export.AbstractDomainObjectsExporter;
|
||||||
|
import org.libreccm.export.IdSequence;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public abstract class AbstractAttachmentListsExporter
|
||||||
|
extends AbstractDomainObjectsExporter<ContentItem> {
|
||||||
|
|
||||||
|
// public static String generateFileAttachmentsListUuid(
|
||||||
|
// final ContentItem item) {
|
||||||
|
//
|
||||||
|
// return generateListUuid(item, "files");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static String generateImagesListUuid(
|
||||||
|
// final ContentItem item) {
|
||||||
|
//
|
||||||
|
// return generateListUuid(item, "images");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static String generateLinksListUuid(
|
||||||
|
// final ContentItem item) {
|
||||||
|
//
|
||||||
|
// return generateListUuid(item, "links");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static String generateSideNotesListUuid(
|
||||||
|
// final ContentItem item) {
|
||||||
|
//
|
||||||
|
// return generateListUuid(item, "side-notes");
|
||||||
|
// }
|
||||||
|
|
||||||
|
public final static String generateListUuid(final ContentItem item,
|
||||||
|
final String listName) {
|
||||||
|
|
||||||
|
final byte[] uuidSource = String.format(
|
||||||
|
"%s/%s-%s",
|
||||||
|
WebConfig.getInstanceOf().getSiteName(),
|
||||||
|
Objects.requireNonNull(item).getOID().toString(),
|
||||||
|
listName)
|
||||||
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
return UUID.nameUUIDFromBytes(uuidSource).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<ContentItem> exportsType() {
|
||||||
|
return ContentItem.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String exportsBaseDataObjectType() {
|
||||||
|
return ContentItem.BASE_DATA_OBJECT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean includeSubTypes() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertsToType() {
|
||||||
|
return "org.librecms.contentsection.AttachmentList";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getListName();
|
||||||
|
|
||||||
|
protected abstract boolean hasList(ContentItem contentItem);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final List<String> exportDomainObject(
|
||||||
|
final ContentItem contentItem, final Path targetDir) {
|
||||||
|
|
||||||
|
if (!hasList(contentItem)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
final String uuid = generateListUuid(contentItem, getListName());
|
||||||
|
final Path listTargetFilePath = generateTargetFilePath(targetDir, uuid);
|
||||||
|
final File listTargetFile = listTargetFilePath.toFile();
|
||||||
|
|
||||||
|
final JsonFactory jsonFactory = new JsonFactory();
|
||||||
|
try(JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
.createGenerator(listTargetFile, JsonEncoding.UTF8)) {
|
||||||
|
|
||||||
|
jsonGenerator.writeStartObject();
|
||||||
|
|
||||||
|
jsonGenerator.writeNumberField("listId",
|
||||||
|
IdSequence.getInstance().nextId());
|
||||||
|
jsonGenerator.writeStringField("uuid", uuid);
|
||||||
|
|
||||||
|
jsonGenerator.writeStringField("contentItem", generateUuid(contentItem));
|
||||||
|
|
||||||
|
jsonGenerator.writeStringField("name", getListName());
|
||||||
|
|
||||||
|
jsonGenerator.writeNumberField("order", 1);
|
||||||
|
|
||||||
|
jsonGenerator.writeEndObject();
|
||||||
|
|
||||||
|
} catch(IOException ex) {
|
||||||
|
throw new UncheckedWrapperException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Arrays.asList(new String[]{uuid});
|
||||||
|
|
||||||
|
// final String fileAttachmentsListUuid = generateFileAttachmentsListUuid(
|
||||||
|
// contentItem);
|
||||||
|
// final String imagesListUuid = generateImagesListUuid(contentItem);
|
||||||
|
// final String linksListUuid = generateLinksListUuid(contentItem);
|
||||||
|
// final String sideNotesListUuid = generateSideNotesListUuid(contentItem);
|
||||||
|
//
|
||||||
|
// final Path filesListTargetFilePath = generateTargetFilePath(
|
||||||
|
// targetDir, fileAttachmentsListUuid);
|
||||||
|
// final Path imagesListTargetFilePath = generateTargetFilePath(
|
||||||
|
// targetDir, imagesListUuid);
|
||||||
|
// final Path linksListTargetFilePath = generateTargetFilePath(
|
||||||
|
// targetDir, linksListUuid);
|
||||||
|
// final Path sideNotesListTargetFilePath = generateTargetFilePath(
|
||||||
|
// targetDir, sideNotesListUuid);
|
||||||
|
//
|
||||||
|
// final JsonFactory jsonFactory = new JsonFactory();
|
||||||
|
//
|
||||||
|
// final File filesListTargetFile = filesListTargetFilePath.toFile();
|
||||||
|
// try (JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
// .createGenerator(filesListTargetFile, JsonEncoding.UTF8)) {
|
||||||
|
//
|
||||||
|
// writeAttachementsList(
|
||||||
|
// fileAttachmentsListUuid,
|
||||||
|
// "files",
|
||||||
|
// 1,
|
||||||
|
// jsonGenerator,
|
||||||
|
// contentItem);
|
||||||
|
//
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// throw new UncheckedWrapperException(ex);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// final File imagesListTargetFile = imagesListTargetFilePath.toFile();
|
||||||
|
// try (JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
// .createGenerator(imagesListTargetFile, JsonEncoding.UTF8)) {
|
||||||
|
//
|
||||||
|
// writeAttachementsList(
|
||||||
|
// imagesListUuid,
|
||||||
|
// "images",
|
||||||
|
// 1,
|
||||||
|
// jsonGenerator,
|
||||||
|
// contentItem);
|
||||||
|
//
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// throw new UncheckedWrapperException(ex);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// final File linksListTargetFile = linksListTargetFilePath.toFile();
|
||||||
|
// try (JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
// .createGenerator(linksListTargetFile, JsonEncoding.UTF8)) {
|
||||||
|
//
|
||||||
|
// writeAttachementsList(
|
||||||
|
// linksListUuid,
|
||||||
|
// "links",
|
||||||
|
// 1,
|
||||||
|
// jsonGenerator,
|
||||||
|
// contentItem);
|
||||||
|
//
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// throw new UncheckedWrapperException(ex);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// final File sideNotesListTargetFile = sideNotesListTargetFilePath
|
||||||
|
// .toFile();
|
||||||
|
// try (JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
// .createGenerator(sideNotesListTargetFile, JsonEncoding.UTF8)) {
|
||||||
|
//
|
||||||
|
// writeAttachementsList(
|
||||||
|
// sideNotesListUuid,
|
||||||
|
// "sideNotes",
|
||||||
|
// 1,
|
||||||
|
// jsonGenerator,
|
||||||
|
// contentItem);
|
||||||
|
//
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// throw new UncheckedWrapperException(ex);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return Arrays.asList(new String[]{
|
||||||
|
// fileAttachmentsListUuid,
|
||||||
|
// imagesListUuid,
|
||||||
|
// linksListUuid,
|
||||||
|
// sideNotesListUuid
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void writeAttachementsList(final String listUuid,
|
||||||
|
// final String name,
|
||||||
|
// final long order,
|
||||||
|
// final JsonGenerator jsonGenerator,
|
||||||
|
// final ContentItem item)
|
||||||
|
// throws IOException {
|
||||||
|
//
|
||||||
|
// jsonGenerator.writeStartObject();
|
||||||
|
//
|
||||||
|
// jsonGenerator.writeNumberField("listId",
|
||||||
|
// IdSequence.getInstance().nextId());
|
||||||
|
// jsonGenerator.writeStringField("uuid", listUuid);
|
||||||
|
//
|
||||||
|
// jsonGenerator.writeStringField("contentItem", generateUuid(item));
|
||||||
|
//
|
||||||
|
// jsonGenerator.writeStringField("name", name);
|
||||||
|
//
|
||||||
|
// jsonGenerator.writeNumberField("order", order);
|
||||||
|
//
|
||||||
|
// jsonGenerator.writeEndObject();
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ public abstract class AbstractCcmObjectsExporter<T extends ACSObject>
|
||||||
|
|
||||||
final String uuid = generateUuid(domainObject);
|
final String uuid = generateUuid(domainObject);
|
||||||
final Path targetFilePath = generateTargetFilePath(
|
final Path targetFilePath = generateTargetFilePath(
|
||||||
targetDir, exportsType().getName(), uuid);
|
targetDir, convertsToType(), uuid);
|
||||||
|
|
||||||
final JsonFactory jsonFactory = new JsonFactory();
|
final JsonFactory jsonFactory = new JsonFactory();
|
||||||
try (JsonGenerator jsonGenerator = jsonFactory
|
try (JsonGenerator jsonGenerator = jsonFactory
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,10 @@ public abstract class AbstractDomainObjectsExporter<T extends DomainObject> {
|
||||||
*/
|
*/
|
||||||
public abstract String exportsBaseDataObjectType();
|
public abstract String exportsBaseDataObjectType();
|
||||||
|
|
||||||
|
protected boolean includeSubTypes() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the fully qualified class name of the type to which the domain
|
* Provides the fully qualified class name of the type to which the domain
|
||||||
* objects handled by the implementation are converted.
|
* objects handled by the implementation are converted.
|
||||||
|
|
@ -149,12 +153,12 @@ public abstract class AbstractDomainObjectsExporter<T extends DomainObject> {
|
||||||
final DataCollection dataCollection = session
|
final DataCollection dataCollection = session
|
||||||
.retrieve(exportsBaseDataObjectType());
|
.retrieve(exportsBaseDataObjectType());
|
||||||
|
|
||||||
final List<T> domainObjects = new ArrayList<>();
|
// final List<T> domainObjects = new ArrayList<>();
|
||||||
|
final List<String> uuids = new ArrayList<>();
|
||||||
while (dataCollection.next()) {
|
while (dataCollection.next()) {
|
||||||
|
|
||||||
final DataObject dataObject = dataCollection.getDataObject();
|
final DataObject dataObj = dataCollection.getDataObject();
|
||||||
final DomainObject domainObject = DomainObjectFactory
|
final T domainObject = (T) DomainObjectFactory.newInstance(dataObj);
|
||||||
.newInstance(dataObject);
|
|
||||||
|
|
||||||
// if (!(exportsType().isAssignableFrom(domainObject.getClass()))) {
|
// if (!(exportsType().isAssignableFrom(domainObject.getClass()))) {
|
||||||
// throw new ExportException(String.format(
|
// throw new ExportException(String.format(
|
||||||
|
|
@ -162,23 +166,33 @@ public abstract class AbstractDomainObjectsExporter<T extends DomainObject> {
|
||||||
// exportsType().getName(),
|
// exportsType().getName(),
|
||||||
// domainObject.getClass().getName()));
|
// domainObject.getClass().getName()));
|
||||||
// }
|
// }
|
||||||
if (!exportsType().equals(domainObject.getClass())) {
|
if (includeSubTypes()) {
|
||||||
// Is not exact type (sub class?). Skip.
|
if (!(exportsType().isAssignableFrom(domainObject.getClass()))) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!exportsType().equals(domainObject.getClass())) {
|
||||||
|
// Is not exact type (sub class?). Skip.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
domainObjects.add((T) domainObject);
|
// domainObjects.add((T) domainObject);
|
||||||
}
|
|
||||||
|
|
||||||
final List<String> uuids = new ArrayList<>();
|
|
||||||
for (final T domainObject : domainObjects) {
|
|
||||||
System.out.printf("Exporting domain object %s...%n",
|
System.out.printf("Exporting domain object %s...%n",
|
||||||
domainObject.getOID().toString());
|
domainObject.getOID().toString());
|
||||||
final List<String> createdUuids = exportDomainObject(domainObject,
|
final List<String> createdUuids = exportDomainObject(
|
||||||
targetDir);
|
domainObject,
|
||||||
|
targetDir);
|
||||||
uuids.addAll(createdUuids);
|
uuids.addAll(createdUuids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for (final T domainObject : domainObjects) {
|
||||||
|
// System.out.printf("Exporting domain object %s...%n",
|
||||||
|
// domainObject.getOID().toString());
|
||||||
|
// final List<String> createdUuids = exportDomainObject(domainObject,
|
||||||
|
// targetDir);
|
||||||
|
// uuids.addAll(createdUuids);
|
||||||
|
// }
|
||||||
return uuids;
|
return uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -42,6 +41,11 @@ public class TaskDependenciesExporter
|
||||||
return "org.libreccm.workflow.TaskDependency";
|
return "org.libreccm.workflow.TaskDependency";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean includeSubTypes() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> exportDomainObject(final Task domainObject,
|
protected List<String> exportDomainObject(final Task domainObject,
|
||||||
final Path targetDir) {
|
final Path targetDir) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue