CCM NG/ccm-cms: Next part of RelatedInfoStep

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4913 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 485b4a85b0
pull/2/head
jensp 2017-08-20 18:10:32 +00:00
parent e194d845c9
commit 2b57568d65
9 changed files with 633 additions and 43 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2017 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.ui.authoring.assets.relatedinfo;
import org.librecms.contentsection.Asset;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class AttachmentTableRow {
private long attachmentId;
private String title;
private Class<? extends Asset> type;
public long getAttachmentId() {
return attachmentId;
}
public void setAttachmentId(final long attachmentId) {
this.attachmentId = attachmentId;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public Class<? extends Asset> getType() {
return type;
}
public void setType(final Class<? extends Asset> type) {
this.type = type;
}
}

View File

@ -0,0 +1,197 @@
/*
* Copyright (C) 2017 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.ui.authoring.assets.relatedinfo;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ItemAttachment;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class AttachmentsTable extends Table {
protected static final int COL_TITLE = 0;
protected static final int COL_TYPE = 1;
protected static final int COL_MOVE = 2;
protected static final int COL_REMOVE = 3;
private final RelatedInfoStep relatedInfoStep;
private final ItemSelectionModel itemSelectionModel;
private final AttachmentListSelectionModel attachmentListSelectionModel;
private final AttachmentSelectionModel selectedAttachmentModel;
private final AttachmentSelectionModel moveAttachmentModel;
private final StringParameter selectedLanguageParam;
public AttachmentsTable(
final RelatedInfoStep relatedInfoStep,
final ItemSelectionModel itemSelectionModel,
final AttachmentListSelectionModel attachmentListSelectionModel,
final AttachmentSelectionModel selectedAttachmentModel,
final AttachmentSelectionModel moveAttachmentModel,
final StringParameter selectedLanguageParam) {
super();
this.relatedInfoStep = relatedInfoStep;
this.itemSelectionModel = itemSelectionModel;
this.attachmentListSelectionModel = attachmentListSelectionModel;
this.selectedAttachmentModel = selectedAttachmentModel;
this.moveAttachmentModel = moveAttachmentModel;
this.selectedLanguageParam = selectedLanguageParam;
final TableColumnModel columnModel = super.getColumnModel();
columnModel.add(new TableColumn(
COL_TITLE,
new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.title",
CmsConstants.CMS_BUNDLE))));
columnModel.add(new TableColumn(
COL_TYPE,
new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.type",
CmsConstants.CMS_BUNDLE))));
columnModel.add(new TableColumn(
COL_MOVE,
new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.move"))));
columnModel.add(new TableColumn(
COL_REMOVE,
new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.remove"))));
super
.setModelBuilder(new AttachmentsTableModelBuilder(
itemSelectionModel,
attachmentListSelectionModel,
moveAttachmentModel,
selectedLanguageParam));
super
.getColumn(COL_MOVE)
.setCellRenderer(new ControlLinkCellRenderer());
super
.getColumn(COL_REMOVE)
.setCellRenderer(new ControlLinkCellRenderer());
super
.addTableActionListener(new TableActionListener() {
@Override
public void cellSelected(final TableActionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final TableColumn column = getColumnModel()
.get(event.getColumn());
switch (column.getModelIndex()) {
case COL_MOVE: {
if (moveAttachmentModel
.getSelectedKey(state) == null) {
moveAttachmentModel
.setSelectedKey(state,
Long.parseLong(
(String) event
.getRowKey()));
} else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RelatedInfoStepController controller
= cdiUtil
.findBean(
RelatedInfoStepController.class);
final ItemAttachment<?> attachment
= moveAttachmentModel
.getSelectedAttachment(state);
final Long destId = Long.parseLong(
(String) event.getRowKey());
controller.moveAfter(
attachmentListSelectionModel
.getSelectedAttachmentList(state),
attachment,
destId);
moveAttachmentModel.clearSelection(state);
}
break;
}
case COL_REMOVE: {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RelatedInfoStepController controller = cdiUtil
.findBean(RelatedInfoStepController.class);
controller.removeAttachment(Long.parseLong(
(String) event.getRowKey()));
}
default:
throw new IllegalArgumentException(String
.format("Illegal column index: %d",
column.getModelIndex()));
}
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void headSelected(final TableActionEvent event) {
//Nothing
}
});
}
private class ControlLinkCellRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (C) 2017 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.ui.authoring.assets.relatedinfo;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
import org.librecms.assets.AssetTypeInfo;
import org.librecms.assets.AssetTypesManager;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class AttachmentsTableModel implements TableModel {
private final PageState state;
private final AttachmentSelectionModel moveAttachmentModel;
private final Iterator<AttachmentTableRow> iterator;
private AttachmentTableRow currentRow;
AttachmentsTableModel(
final List<AttachmentTableRow> rows,
final PageState state,
final AttachmentSelectionModel moveAttachmentModel) {
this.state = state;
this.moveAttachmentModel = moveAttachmentModel;
this.iterator = rows.iterator();
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public boolean nextRow() {
if (iterator.hasNext()) {
currentRow = iterator.next();
return true;
} else {
return false;
}
}
@Override
public Object getElementAt(final int columnIndex) {
switch (columnIndex) {
case AttachmentsTable.COL_TITLE:
return currentRow.getTitle();
case AttachmentsTable.COL_TYPE: {
final AssetTypesManager typesManager = CdiUtil
.createCdiUtil()
.findBean(AssetTypesManager.class);
final AssetTypeInfo typeInfo = typesManager
.getAssetTypeInfo(currentRow.getType());
final ResourceBundle bundle = ResourceBundle
.getBundle(typeInfo.getLabelBundle());
return bundle.getString(typeInfo.getLabelKey());
}
case AttachmentsTable.COL_MOVE:
if (moveAttachmentModel.getSelectedAttachment(state) == null) {
return new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.move",
CmsConstants.CMS_BUNDLE));
} else {
return new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.move_here",
CmsConstants.CMS_BUNDLE));
}
case AttachmentsTable.COL_REMOVE:
return new Label(new GlobalizedMessage(
"cms.ui.authoring.assets.related_info_step.attachment.remove",
CmsConstants.CMS_BUNDLE));
default:
throw new IllegalArgumentException(String.format(
"Illegal column index %d.", columnIndex));
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return currentRow.getAttachmentId();
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright (C) 2017 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.ui.authoring.assets.relatedinfo;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel;
import com.arsdigita.util.LockableImpl;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.ContentItem;
import java.util.List;
import java.util.Locale;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class AttachmentsTableModelBuilder
extends LockableImpl
implements TableModelBuilder {
private final ItemSelectionModel itemSelectionModel;
private final AttachmentListSelectionModel listSelectionModel;
private final AttachmentSelectionModel moveAttachmentModel;
private final StringParameter selectedLanguageParam;
public AttachmentsTableModelBuilder(
final ItemSelectionModel itemSelectionModel,
final AttachmentListSelectionModel listSelectionModel,
final AttachmentSelectionModel moveAttachmentModel,
final StringParameter selectedLanguageParam) {
super();
this.itemSelectionModel = itemSelectionModel;
this.listSelectionModel = listSelectionModel;
this.moveAttachmentModel = moveAttachmentModel;
this.selectedLanguageParam = selectedLanguageParam;
}
@Override
public TableModel makeModel(final Table table, final PageState state) {
final ContentItem selectedItem = itemSelectionModel
.getSelectedItem(state);
final AttachmentList list = listSelectionModel.getSelectedAttachmentList(state);
final String selectedLanguage = (String) state
.getValue(selectedLanguageParam);
final Locale selectedLocale = new Locale(selectedLanguage);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RelatedInfoStepController controller = cdiUtil
.findBean(RelatedInfoStepController.class);
final List<AttachmentTableRow> rows = controller
.retrieveAttachments(selectedItem, list, selectedLocale);
return new AttachmentsTableModel(rows, state, moveAttachmentModel);
}
}

View File

@ -29,11 +29,15 @@ import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect; import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.TextArea; import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.GlobalizedParameterListener;
import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.parameters.StringIsLettersOrDigitsValidationListener;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
@ -224,6 +228,7 @@ class RelatedInfoListForm
super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.name", super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.name",
CmsConstants.CMS_BUNDLE))); CmsConstants.CMS_BUNDLE)));
nameField = new TextField("attachmentListName"); nameField = new TextField("attachmentListName");
nameField.addValidationListener(new AssetListNameValidator());
super.add(nameField); super.add(nameField);
super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.title", super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.title",
@ -365,13 +370,35 @@ class RelatedInfoListForm
@Override @Override
public void submitted(final FormSectionEvent event) public void submitted(final FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
final PageState state = event.getPageState(); final PageState state = event.getPageState();
if (saveCancelSection.getCancelButton().isSelected(state)) { if (saveCancelSection.getCancelButton().isSelected(state)) {
listSelectionModel.clearSelection(state); listSelectionModel.clearSelection(state);
relatedInfoStep.showAttachmentListTable(state); relatedInfoStep.showAttachmentListTable(state);
} }
} }
private class AssetListNameValidator extends GlobalizedParameterListener {
public AssetListNameValidator() {
super.setError(new GlobalizedMessage(
"cms.ui.assetlist.name_cant_start_with_dot",
CmsConstants.CMS_BUNDLE));
}
@Override
public void validate(final ParameterEvent event) throws
FormProcessException {
final ParameterData data = event.getParameterData();
final String value = (String) data.getValue();
if (value.startsWith(".")) {
data.addError(getError());
}
}
}
} }

View File

@ -109,15 +109,18 @@ class RelatedInfoListTable extends Table {
moveListModel, moveListModel,
selectedLanguageParam)); selectedLanguageParam));
super
.getColumn(COL_NAME)
.setCellRenderer(new ControlLinkCellRenderer());
super super
.getColumn(COL_EDIT) .getColumn(COL_EDIT)
.setCellRenderer(new EditCellRenderer()); .setCellRenderer(new ControlLinkCellRenderer());
super super
.getColumn(COL_MOVE) .getColumn(COL_MOVE)
.setCellRenderer(new MoveCellRenderer()); .setCellRenderer(new ControlLinkCellRenderer());
super super
.getColumn(COL_DELETE) .getColumn(COL_DELETE)
.setCellRenderer(new DeleteCellRenderer()); .setCellRenderer(new ControlLinkCellRenderer());
super super
.addTableActionListener(new TableActionListener() { .addTableActionListener(new TableActionListener() {
@ -132,6 +135,13 @@ class RelatedInfoListTable extends Table {
.get(event.getColumn()); .get(event.getColumn());
switch (column.getModelIndex()) { switch (column.getModelIndex()) {
case COL_NAME:
selectedListModel
.setSelectedKey(state,
Long.parseLong((String) event
.getRowKey()));
relatedInfoStep.showAttachmentsTable(state);
break;
case COL_EDIT: case COL_EDIT:
selectedListModel selectedListModel
.setSelectedKey(state, .setSelectedKey(state,
@ -168,17 +178,22 @@ class RelatedInfoListTable extends Table {
moveListModel.clearSelection(state); moveListModel.clearSelection(state);
} }
break; break;
case COL_DELETE: case COL_DELETE: {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RelatedInfoStepController controller = cdiUtil final RelatedInfoStepController controller = cdiUtil
.findBean(RelatedInfoStepController.class); .findBean(RelatedInfoStepController.class);
controller.deleteList(Long controller.deleteList(Long
.parseLong((String) event.getRowKey())); .parseLong((String) event.getRowKey()));
break;
}
default:
throw new IllegalArgumentException(String
.format("Illegal column index: %d",
column.getModelIndex()));
} }
} }
@Override @Override
public void headSelected(final TableActionEvent event) { public void headSelected(final TableActionEvent event) {
//Nothing //Nothing
} }
@ -186,39 +201,7 @@ class RelatedInfoListTable extends Table {
}); });
} }
private class MoveCellRenderer implements TableCellRenderer { private class ControlLinkCellRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
}
private class EditCellRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
}
private class DeleteCellRenderer implements TableCellRenderer {
@Override @Override
public Component getComponent(final Table table, public Component getComponent(final Table table,
@ -233,5 +216,53 @@ class RelatedInfoListTable extends Table {
} }
} }
//
// private class MoveCellRenderer implements TableCellRenderer {
//
// @Override
// public Component getComponent(final Table table,
// final PageState state,
// final Object value,
// final boolean isSelected,
// final Object key,
// final int row,
// final int column) {
//
// return new ControlLink((Component) value);
// }
//
// }
//
// private class EditCellRenderer implements TableCellRenderer {
//
// @Override
// public Component getComponent(final Table table,
// final PageState state,
// final Object value,
// final boolean isSelected,
// final Object key,
// final int row,
// final int column) {
//
// return new ControlLink((Component) value);
// }
//
// }
//
// private class DeleteCellRenderer implements TableCellRenderer {
//
// @Override
// public Component getComponent(final Table table,
// final PageState state,
// final Object value,
// final boolean isSelected,
// final Object key,
// final int row,
// final int column) {
//
// return new ControlLink((Component) value);
// }
//
//}
} }

View File

@ -58,8 +58,7 @@ class RelatedInfoListTableModelBuilder
} }
@Override @Override
public TableModel makeModel(final Table table, public TableModel makeModel(final Table table, final PageState state) {
final PageState state) {
final ContentItem selectedItem = itemSelectionModel final ContentItem selectedItem = itemSelectionModel
.getSelectedItem(state); .getSelectedItem(state);

View File

@ -151,4 +151,10 @@ public class RelatedInfoStep extends ResettableContainer {
listToFirstLink.setVisible(state, false); listToFirstLink.setVisible(state, false);
} }
void showAttachmentsTable(final PageState state) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
} }

View File

@ -25,6 +25,8 @@ import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.AttachmentListManager; import org.librecms.contentsection.AttachmentListManager;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ItemAttachment;
import org.librecms.contentsection.ItemAttachmentManager;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -56,6 +58,9 @@ class RelatedInfoStepController {
@Inject @Inject
private EntityManager entityManager; private EntityManager entityManager;
@Inject
private ItemAttachmentManager itemAttachmentManager;
private Locale defaultLocale; private Locale defaultLocale;
@PostConstruct @PostConstruct
@ -167,6 +172,13 @@ class RelatedInfoStepController {
entityManager.merge(toMove); entityManager.merge(toMove);
} }
protected void moveAfter(final AttachmentList list,
final ItemAttachment<?> attachment,
final long destId) {
//ToDo
throw new UnsupportedOperationException();
}
protected void deleteList(final Long listId) { protected void deleteList(final Long listId) {
final AttachmentList list = attachmentListManager final AttachmentList list = attachmentListManager
@ -179,7 +191,20 @@ class RelatedInfoStepController {
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
List<AttachmentListTableRow> retrieveAttachmentLists( protected void removeAttachment(final long attachmentId) {
final ItemAttachment<?> attachment = itemAttachmentManager
.findById(attachmentId)
.orElseThrow(() -> new IllegalArgumentException(String
.format("No ItemAttachment with ID %d in the database.",
attachmentId)));
entityManager.remove(attachment);
}
@Transactional(Transactional.TxType.REQUIRED)
protected List<AttachmentListTableRow> retrieveAttachmentLists(
final ContentItem forContentItem, final ContentItem forContentItem,
final Locale selectedLocale) { final Locale selectedLocale) {
@ -197,6 +222,26 @@ class RelatedInfoStepController {
} }
@Transactional(Transactional.TxType.REQUIRED)
protected List<AttachmentTableRow> retrieveAttachments(
final ContentItem selectedItem,
final AttachmentList fromList,
final Locale selectedLocale) {
final AttachmentList list = attachmentListManager
.getAttachmentList(fromList.getListId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No AttachmentList with ID %d in the database.",
fromList.getListId())));
return list
.getAttachments()
.stream()
.map(attachment -> buildAttachmentTableRow(attachment,
selectedLocale))
.collect(Collectors.toList());
}
private AttachmentListTableRow buildAttachmentListTableRow( private AttachmentListTableRow buildAttachmentListTableRow(
final AttachmentList attachmentList, final AttachmentList attachmentList,
final Locale selectedLocale) { final Locale selectedLocale) {
@ -231,6 +276,35 @@ class RelatedInfoStepController {
return row; return row;
} }
private AttachmentTableRow buildAttachmentTableRow(
final ItemAttachment<?> attachment,
final Locale selectedLocale) {
final AttachmentTableRow row = new AttachmentTableRow();
row.setAttachmentId(attachment.getAttachmentId());
if (attachment.getAsset().getTitle().hasValue(selectedLocale)) {
row.setTitle(attachment
.getAsset()
.getTitle()
.getValue(selectedLocale));
} else if (attachment.getAsset().getTitle().hasValue(defaultLocale)) {
row.setTitle(attachment
.getAsset()
.getTitle()
.getValue(defaultLocale));
} else {
row.setTitle(attachment
.getAsset()
.getTitle()
.getValue());
}
row.setType(attachment.getAsset().getClass());
return row;
}
private String shortenDescription(final String description) { private String shortenDescription(final String description) {
if (description.trim().length() < 140) { if (description.trim().length() < 140) {