Skip to content
Merged
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 @@ -15,6 +15,7 @@
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.cache.FieldsCache;
import com.dotmarketing.db.HibernateUtil;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.exception.DotHibernateException;
import com.dotmarketing.portal.struts.DotPortletAction;
import com.dotmarketing.portlets.contentlet.action.ImportAuditUtil.ImportAuditResults;
Expand Down Expand Up @@ -376,13 +377,29 @@ private void _downloadCSVTemplate(ActionRequest req, ActionResponse res, Portlet
ActionResponseImpl resImpl = (ActionResponseImpl)res;
HttpServletResponse httpRes = resImpl.getHttpServletResponse();

ImportContentletsForm importForm = (ImportContentletsForm) form;
if (!UtilMethods.isSet(importForm.getStructure())) {
SessionMessages.add(req, ERROR, "structure-type-is-required");
setForward(req, PORTLET_EXT_CONTENTLET_IMPORT_CONTENTLETS);
return;
}

// The fields must be resolved before any download header is committed, otherwise a
// failed lookup leaves the response flagged as an attachment with an empty error body
final List<Field> fields;
try {
fields = FieldsCache.getFieldsByStructureInode(importForm.getStructure());
} catch (final DotStateException e) {
Logger.warn(this, "Unable to generate CSV template: selected Content Type does not exist", e);
SessionMessages.add(req, ERROR, "Workflow-does-not-exists-content-type");
setForward(req, PORTLET_EXT_CONTENTLET_IMPORT_CONTENTLETS);
return;
}

httpRes.setContentType("application/octet-stream");
httpRes.setHeader("Content-Disposition", "attachment; filename=\"CSV_Template.csv\"");

ServletOutputStream out = httpRes.getOutputStream();
ImportContentletsForm importForm = (ImportContentletsForm) form;

List<Field> fields = FieldsCache.getFieldsByStructureInode(importForm.getStructure());
for(int i = 0; i < fields.size(); i++) {
Field field = fields.get(i);
if (ImportUtil.isImportableField(field)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
}

function downloadCSVExample() {
var structureInode = dijit.byId("structuresSelect").attr('value');
if (!structureInode) {
showDotCMSSystemMessage('<%= UtilMethods.escapeSingleQuotes(LanguageUtil.get(pageContext, "structure-type-is-required")) %>', true);
return;
}
var href = '<portlet:actionURL>';
href += '<portlet:param name="struts_action" value="/ext/contentlet/import_contentlets" />';
href += '<portlet:param name="cmd" value="downloadCSVTemplate" />';
Expand Down
Loading