Skip to content

Implemented poor-mans template-choosing for imports, disabled the FolderChooser in UploadDialog and improved documentation #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CSVImportResource {
/**
* Import process logger.
*/
private static Logger logger = LoggerFactory.getLogger(CSVImportResource.class);
private static final Logger logger = LoggerFactory.getLogger(CSVImportResource.class);

/**
* Sets the content repository.
Expand Down Expand Up @@ -96,8 +96,7 @@ public void setAuthorizedGroups(List<String> authorizedGroups) {
@PostMapping(value = "importcsv/uploadfile",
produces = "text/json",
consumes = "multipart/form-data")
public ResponseEntity importCSV(@HeaderParam("site") String siteId,
@HeaderParam("folderUri") String folderUri,
public ResponseEntity importCSV(@RequestParam("template") String template,
@RequestParam("file") MultipartFile file) throws IOException {

// Check that the user is a member of the requisite group
Expand All @@ -106,7 +105,6 @@ public ResponseEntity importCSV(@HeaderParam("site") String siteId,
}

boolean autoPublish = false;
String template = "default";
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()));
CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
CSVParserHelper handler = new CSVParserHelper(autoPublish, contentRepository, logger);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
package com.coremedia.csv.studio.importer {
import com.coremedia.cap.content.Content;
import com.coremedia.cms.editor.sdk.upload.FileWrapper;
import com.coremedia.cms.editor.sdk.upload.UploadManager;
import com.coremedia.cms.editor.sdk.upload.UploadSettings;
import com.coremedia.cms.editor.sdk.upload.dialog.FileContainer;
import com.coremedia.cms.editor.sdk.upload.dialog.FileContainersObservable;
import com.coremedia.cms.editor.sdk.upload.dialog.UploadDialog;
import com.coremedia.cms.editor.sdk.util.MessageBoxUtil;
import com.coremedia.cms.editor.sdk.util.StudioConfigurationUtil;
import com.coremedia.ui.data.ValueExpression;
import com.coremedia.ui.data.ValueExpressionFactory;
import com.coremedia.ui.data.error.RemoteError;
import com.coremedia.ui.data.impl.RemoteService;
import com.coremedia.ui.logging.Logger;
import com.coremedia.ui.util.EventUtil;

import ext.Ext;

import ext.MessageBox;
import ext.container.Container;

import js.XMLHttpRequest;

public class CSVImportDialogBase extends UploadDialog {

public static const REPORTING_SETTINGS_NAME:String = "ReportingSettings";
public static const DEFAULT_TEMPLATE_SETTING:String = "defaultImportTemplate";

private var fileContainers:FileContainersObservable;
private var validationExpression:ValueExpression;
private var uploadDropAreaDisabled:Boolean;

public function CSVImportDialogBase(config:CSVImportDialogBase = null) {
super(config);
showFolderChooser = false; // disables the FolderChooser, as it is not used and confuses the user otherwise
}

protected function getDefaultImportTemplate():String {
var configuration:* = StudioConfigurationUtil.getConfiguration(REPORTING_SETTINGS_NAME, DEFAULT_TEMPLATE_SETTING);
return (configuration == null) ? 'default' : configuration;
}

/**
Expand Down Expand Up @@ -165,6 +172,10 @@ public class CSVImportDialogBase extends UploadDialog {
formData.append('contentName', contentName);
}

var defaultImportTemplate:String = getDefaultImportTemplate();
Logger.info("Template used for import: " + defaultImportTemplate);
formData.append('template', defaultImportTemplate);

uploadRequest = new XMLHttpRequest();

uploadRequest.open('POST', url, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<ui:NestedRulesPlugin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns="exml:ext.config"
xmlns:exml="http://www.jangaroo.net/exml/0.8"
xmlns:ui="exml:com.coremedia.ui.config"
xmlns:editor="exml:com.coremedia.cms.editor.sdk.config"
xmlns:local="exml:com.coremedia.csv.studio.config">
Expand All @@ -24,7 +25,7 @@

<!-- Add to the toolbar visible from the library's repository browsing view -->
<editor:RepositoryToolbar>
<editor:plugins>
<editor:plugins exml:mode="append">
<ui:AddItemsPlugin>
<ui:items>
<!-- Add a CSV export icon to the toolbar -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@
<locale>en-US</locale>
<master/>
<settings><Struct xmlns="http://www.coremedia.com/2008/struct" xmlns:xlink="http://www.w3.org/1999/xlink">
<StringProperty Name="defaultImportTemplate">default</StringProperty>
<MarkupProperty Name="documentation" RequiredGrammar="coremedia-richtext-1.0" Grammar="coremedia-richtext-1.0"><div xmlns="http://www.coremedia.com/2003/richtext-1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<pre>CLICK ME, to read the list of the default 'cvsHeaders' you can use without a 'csvProperties'-Mapping
Id =&gt; Integer.toString(IdHelper.parseContentId(content.getId()))
Name =&gt; content.getName()
Path =&gt; content.getPath()
URL =&gt; linkFormatter.formatLink(contentBean, null, request, response, false)
Type =&gt; content.getType().getName()
CreationDate =&gt; content.getCreationDate()
CreatedBy =&gt; content.getCreator().getName()
LastModificationDate =&gt; content.getModificationDate()
LastModifiedBy =&gt; content.getModifier().getName()
VersionStatus =&gt; see below
PublicationDate =&gt; contentRepository.getPublicationService().getPublicationDate(content)

protected String getContentVersionStatusString(Content content) {
PublicationService publicationService = contentRepository.getPublicationService();
String status = "";
if (content.isCheckedOut()) {
status = "Checked Out";
} else {
Version version = content.getWorkingVersion();
if (version == null) {
version = content.getCheckedInVersion();
}
if (version != null) {
status = "Checked In";
if (publicationService.isApproved(version)) {
status = "Approved";
}
if (publicationService.isPublished(version)) {
status = "Published";
}
}
if (publicationService.isNew(content)) {
status = "Created";
}
}
return status;
}
</pre></div></MarkupProperty>
<StructProperty Name="templates">
<Struct>
<StructProperty Name="default">
Expand Down
1 change: 1 addition & 0 deletions documentation/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ See the “default” template for an example of how to format custom templates.
To add a column to the CSV exporter output, simply add the desired header to the “csvHeaders” string list in the template. Additionally, the value in this new column will need to be configured.
### Configuring Static Properties (Metadata)
Metadata for a content object must be added to a CSV record via the Java code. Each supported metadata value corresponds to a preset header value, such as "Id", "Name", or "URL." See the “populateContentMetadataFields” method in BaseCSVUtil.java for examples of how to include such properties.
For a list of all currently available metadata fields, see 'documentation' in [ReportingSettings.xml](../csv-test-data/content/Settings/Options/Settings/ReportingSettings.xml)
### Configuring Dynamic Properties
Content properties may be configured dynamically through the “csvProperties” struct in a template, which maps template headers to content properties. To add a new column, create an entry with the header as the key and the property name as the value. Properties defined in a content’s local settings may be accessed through using the "localSettings" property. This will output the entire localSettings for each content reported in Markup, which gives the flexibility to add, remove, or change localSettings for content in bulk.
### Configuring Custom Values
Expand Down