CCM NG: Fixed ItemLifecyclePane
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5157 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
133f39e233
commit
85991a3151
|
|
@ -26,6 +26,7 @@ import org.arsdigita.cms.CMSConfig;
|
||||||
import org.libreccm.categorization.Categorization;
|
import org.libreccm.categorization.Categorization;
|
||||||
import org.libreccm.categorization.Category;
|
import org.libreccm.categorization.Category;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
import org.libreccm.workflow.Task;
|
import org.libreccm.workflow.Task;
|
||||||
import org.libreccm.workflow.TaskManager;
|
import org.libreccm.workflow.TaskManager;
|
||||||
|
|
@ -41,14 +42,17 @@ import org.librecms.lifecycle.Lifecycle;
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
import org.librecms.lifecycle.LifecycleDefinition;
|
||||||
import org.librecms.lifecycle.LifecycleDefinitionRepository;
|
import org.librecms.lifecycle.LifecycleDefinitionRepository;
|
||||||
import org.librecms.lifecycle.LifecycleManager;
|
import org.librecms.lifecycle.LifecycleManager;
|
||||||
|
import org.librecms.lifecycle.LifecycleRepository;
|
||||||
import org.librecms.lifecycle.Phase;
|
import org.librecms.lifecycle.Phase;
|
||||||
|
import org.librecms.lifecycle.PhaseDefinition;
|
||||||
import org.librecms.lifecycle.PhaseRepository;
|
import org.librecms.lifecycle.PhaseRepository;
|
||||||
import org.librecms.workflow.CmsTask;
|
import org.librecms.workflow.CmsTask;
|
||||||
import org.librecms.workflow.CmsTaskType;
|
import org.librecms.workflow.CmsTaskType;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -60,14 +64,18 @@ import javax.transaction.Transactional;
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class ItemLifecycleAdminController {
|
class ItemLifecycleAdminController implements Serializable {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager
|
private static final Logger LOGGER = LogManager
|
||||||
.getLogger(ItemLifecycleAdminController.class);
|
.getLogger(ItemLifecycleAdminController.class);
|
||||||
|
private static final long serialVersionUID = -6482423583933975632L;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ConfigurationManager confManager;
|
private ConfigurationManager confManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentItemRepository itemRepo;
|
private ContentItemRepository itemRepo;
|
||||||
|
|
||||||
|
|
@ -80,6 +88,9 @@ public class ItemLifecycleAdminController {
|
||||||
@Inject
|
@Inject
|
||||||
private LifecycleManager lifecycleManager;
|
private LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private LifecycleRepository lifecycleRepo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PhaseRepository phaseRepo;
|
private PhaseRepository phaseRepo;
|
||||||
|
|
||||||
|
|
@ -151,12 +162,11 @@ public class ItemLifecycleAdminController {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public LifecycleDefinition getDefinitionOfLifecycle(final ContentItem item) {
|
public LifecycleDefinition getDefinitionOfLifecycle(final ContentItem item) {
|
||||||
|
|
||||||
final ContentItem contentItem = itemRepo
|
// final ContentItem contentItem = itemRepo
|
||||||
.findById(item.getObjectId())
|
// .findById(item.getObjectId())
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
// .orElseThrow(() -> new IllegalArgumentException(String
|
||||||
.format("No ContentItem with ID %d in the database.",
|
// .format("No ContentItem with ID %d in the database.",
|
||||||
item.getObjectId())));
|
// item.getObjectId())));
|
||||||
|
|
||||||
final ContentItem liveItem = itemManager
|
final ContentItem liveItem = itemManager
|
||||||
.getLiveVersion(item, ContentItem.class)
|
.getLiveVersion(item, ContentItem.class)
|
||||||
.get();
|
.get();
|
||||||
|
|
@ -164,6 +174,41 @@ public class ItemLifecycleAdminController {
|
||||||
return liveItem.getLifecycle().getDefinition();
|
return liveItem.getLifecycle().getDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected List<ItemPhaseTableRow> findPhasesOfLifecycle(
|
||||||
|
final Lifecycle lifecycle) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(lifecycle);
|
||||||
|
|
||||||
|
final Lifecycle ofLifecycle = lifecycleRepo
|
||||||
|
.findById(lifecycle.getLifecycleId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No Lifecycle with ID %d in the database.",
|
||||||
|
lifecycle.getLifecycleId())));
|
||||||
|
|
||||||
|
return ofLifecycle
|
||||||
|
.getPhases()
|
||||||
|
.stream()
|
||||||
|
.map(this::buildItemPhaseTableRow)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemPhaseTableRow buildItemPhaseTableRow(final Phase phase) {
|
||||||
|
|
||||||
|
final PhaseDefinition definition = phase.getDefinition();
|
||||||
|
|
||||||
|
final ItemPhaseTableRow row = new ItemPhaseTableRow();
|
||||||
|
row.setName(globalizationHelper
|
||||||
|
.getValueFromLocalizedString(definition.getLabel()));
|
||||||
|
row.setDescription(globalizationHelper
|
||||||
|
.getValueFromLocalizedString(definition.getDescription()));
|
||||||
|
row.setStartDate(phase.getStartDateTime());
|
||||||
|
row.setEndDate(phase.getEndDateTime());
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String getPublishingTabUrl(final ContentItem item) {
|
public String getPublishingTabUrl(final ContentItem item) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,12 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.PermissionChecker;
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Michael Pih
|
* @author Michael Pih
|
||||||
* @author Jack Chung
|
* @author Jack Chung
|
||||||
|
|
@ -128,11 +132,21 @@ public class ItemLifecycleAdminPane extends BaseItemPane {
|
||||||
@Override
|
@Override
|
||||||
protected final Object initialValue(final PageState state) {
|
protected final Object initialValue(final PageState state) {
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
final ContentItem item = selectedItem.getContentItem(state);
|
||||||
final Lifecycle lifecycle = item.getLifecycle();
|
|
||||||
|
|
||||||
LOGGER.debug("Returning lifecycle " + lifecycle);
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentItemManager itemManager = cdiUtil
|
||||||
|
.findBean(ContentItemManager.class);
|
||||||
|
final Optional<ContentItem> liveItem = itemManager
|
||||||
|
.getLiveVersion(item, ContentItem.class);
|
||||||
|
if (liveItem.isPresent()) {
|
||||||
|
|
||||||
return lifecycle;
|
final Lifecycle lifecycle = liveItem.get().getLifecycle();
|
||||||
|
LOGGER.debug("Returning lifecycle {}",
|
||||||
|
Objects.toString(lifecycle));
|
||||||
|
return lifecycle;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* 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.lifecycle;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class ItemPhaseTableModel implements TableModel {
|
||||||
|
|
||||||
|
private final Iterator<ItemPhaseTableRow> iterator;
|
||||||
|
private ItemPhaseTableRow currentRow;
|
||||||
|
|
||||||
|
public ItemPhaseTableModel(final List<ItemPhaseTableRow> rows) {
|
||||||
|
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) {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
final Locale locale = globalizationHelper.getNegotiatedLocale();
|
||||||
|
final DateFormat format;
|
||||||
|
if (CMSConfig.getConfig().isHideTimezone()) {
|
||||||
|
format = DateFormat.getDateTimeInstance(
|
||||||
|
DateFormat.FULL, DateFormat.SHORT, locale);
|
||||||
|
} else {
|
||||||
|
format = DateFormat.getDateTimeInstance(
|
||||||
|
DateFormat.FULL, DateFormat.FULL, locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (columnIndex) {
|
||||||
|
case 0:
|
||||||
|
return currentRow.getName();
|
||||||
|
case 1:
|
||||||
|
return currentRow.getDescription();
|
||||||
|
case 2:
|
||||||
|
return format.format(currentRow.getStartDate());
|
||||||
|
case 3:
|
||||||
|
if (currentRow.getEndDate() == null) {
|
||||||
|
return new GlobalizedMessage("cms.ui.lifecycle.forever",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
|
.localize();
|
||||||
|
} else {
|
||||||
|
return currentRow.getEndDate();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Illegal Column Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getKeyAt(final int columnIndex) {
|
||||||
|
|
||||||
|
return currentRow.getPhaseId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -22,18 +22,10 @@ import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Table;
|
import com.arsdigita.bebop.Table;
|
||||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.arsdigita.cms.CMSConfig;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.lifecycle.Phase;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Xixi D'Moon <xdmoon@arsdigita.com>
|
* @author Xixi D'Moon <xdmoon@arsdigita.com>
|
||||||
|
|
@ -52,84 +44,14 @@ class ItemPhaseTableModelBuilder extends AbstractTableModelBuilder {
|
||||||
@Override
|
@Override
|
||||||
public final TableModel makeModel(final Table table,
|
public final TableModel makeModel(final Table table,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
return new Model(lifecycle.getLifecycle(state).getPhases());
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ItemLifecycleAdminController controller = cdiUtil
|
||||||
|
.findBean(ItemLifecycleAdminController.class);
|
||||||
|
|
||||||
|
final List<ItemPhaseTableRow> rows = controller
|
||||||
|
.findPhasesOfLifecycle(lifecycle.getLifecycle(state));
|
||||||
|
|
||||||
|
return new ItemPhaseTableModel(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Model implements TableModel {
|
|
||||||
|
|
||||||
private final List<Phase> phases;
|
|
||||||
private int index = -1;
|
|
||||||
private Phase phase;
|
|
||||||
|
|
||||||
public Model(final List<Phase> phases) {
|
|
||||||
this.phases = phases;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
if (index < phases.size()) {
|
|
||||||
phase = phases.get(index);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getElementAt(final int column) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
|
||||||
.findBean(GlobalizationHelper.class);
|
|
||||||
final Locale locale = globalizationHelper.getNegotiatedLocale();
|
|
||||||
final DateFormat format;
|
|
||||||
if (CMSConfig.getConfig().isHideTimezone()) {
|
|
||||||
format = DateFormat.getDateTimeInstance(
|
|
||||||
DateFormat.FULL, DateFormat.SHORT, locale);
|
|
||||||
} else {
|
|
||||||
format = DateFormat.getDateTimeInstance(
|
|
||||||
DateFormat.FULL, DateFormat.FULL, locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (column) {
|
|
||||||
case 0:
|
|
||||||
return phase.getDefinition().getLabel().getValue(locale);
|
|
||||||
case 1:
|
|
||||||
return phase.getDefinition().getDescription().getValue(
|
|
||||||
locale);
|
|
||||||
case 2:
|
|
||||||
final Date startDate = phase.getStartDateTime();
|
|
||||||
return format.format(startDate);
|
|
||||||
case 3:
|
|
||||||
final Date endDate = phase.getEndDateTime();
|
|
||||||
|
|
||||||
if (endDate == null) {
|
|
||||||
return lz("cms.ui.lifecycle.forever");
|
|
||||||
} else {
|
|
||||||
return format.format(endDate);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getKeyAt(final int column) {
|
|
||||||
return phase.getDefinition().getDefinitionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static String lz(final String key) {
|
|
||||||
final GlobalizedMessage message = new GlobalizedMessage(key,
|
|
||||||
CmsConstants.CMS_BUNDLE);
|
|
||||||
return (String) message.localize();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* 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.lifecycle;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class ItemPhaseTableRow implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8947185134493863779L;
|
||||||
|
|
||||||
|
private long phaseId;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private Date startDate;
|
||||||
|
private Date endDate;
|
||||||
|
|
||||||
|
public long getPhaseId() {
|
||||||
|
return phaseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhaseId(final long phaseId) {
|
||||||
|
this.phaseId = phaseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(final String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getStartDate() {
|
||||||
|
return new Date(startDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(final Date startDate) {
|
||||||
|
this.startDate = new Date(startDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getEndDate() {
|
||||||
|
return new Date(endDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(final Date endDate) {
|
||||||
|
this.endDate = new Date(endDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -22,7 +22,6 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.security.AuthorizationRequired;
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
import org.libreccm.security.RequiresPrivilege;
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ import javax.enterprise.context.RequestScoped;
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class PhaseRepository extends AbstractEntityRepository<Long, Phase>{
|
public class PhaseRepository extends AbstractEntityRepository<Long, Phase>{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1010039772043186415L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<Phase> getEntityClass() {
|
public Class<Phase> getEntityClass() {
|
||||||
return Phase.class;
|
return Phase.class;
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,19 @@
|
||||||
package org.libreccm.auditing;
|
package org.libreccm.auditing;
|
||||||
|
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
|
import org.hibernate.envers.AuditReaderFactory;
|
||||||
import org.hibernate.envers.exception.NotAuditedException;
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
import org.hibernate.envers.query.AuditQuery;
|
import org.hibernate.envers.query.AuditQuery;
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -38,8 +42,12 @@ import java.util.stream.Collectors;
|
||||||
public abstract class AbstractAuditedEntityRepository<K, T>
|
public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
extends AbstractEntityRepository<K, T> {
|
extends AbstractEntityRepository<K, T> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1592329493646101135L;
|
||||||
|
|
||||||
|
// @Inject
|
||||||
|
// private AuditReader auditReader;
|
||||||
@Inject
|
@Inject
|
||||||
private AuditReader auditReader;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
public abstract K getEntityId(final T entity);
|
public abstract K getEntityId(final T entity);
|
||||||
|
|
||||||
|
|
@ -54,6 +62,8 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T retrieveEntityAtRevision(final T entity, final Number revision) {
|
public T retrieveEntityAtRevision(final T entity, final Number revision) {
|
||||||
|
|
||||||
|
final AuditReader auditReader = AuditReaderFactory.get(entityManager);
|
||||||
final AuditQuery query = auditReader.createQuery()
|
final AuditQuery query = auditReader.createQuery()
|
||||||
.forEntitiesAtRevision(getEntityClass(), revision);
|
.forEntitiesAtRevision(getEntityClass(), revision);
|
||||||
query.add(AuditEntity.id().eq(getEntityId(entity)));
|
query.add(AuditEntity.id().eq(getEntityId(entity)));
|
||||||
|
|
@ -89,6 +99,8 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
*/
|
*/
|
||||||
public List<Number> retrieveRevisionNumbersOfEntity(final T entity,
|
public List<Number> retrieveRevisionNumbersOfEntity(final T entity,
|
||||||
final Long objectId) {
|
final Long objectId) {
|
||||||
|
|
||||||
|
final AuditReader auditReader = AuditReaderFactory.get(entityManager);
|
||||||
return auditReader.getRevisions(entity.getClass(), objectId);
|
return auditReader.getRevisions(entity.getClass(), objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,9 +114,11 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
*/
|
*/
|
||||||
public CcmRevision retrieveFirstRevision(final T entity,
|
public CcmRevision retrieveFirstRevision(final T entity,
|
||||||
final Long objectId) {
|
final Long objectId) {
|
||||||
|
|
||||||
final List<Number> revisions = retrieveRevisionNumbersOfEntity(
|
final List<Number> revisions = retrieveRevisionNumbersOfEntity(
|
||||||
entity, objectId);
|
entity, objectId);
|
||||||
|
|
||||||
|
final AuditReader auditReader = AuditReaderFactory.get(entityManager);
|
||||||
return auditReader.findRevision(CcmRevision.class, revisions.get(0));
|
return auditReader.findRevision(CcmRevision.class, revisions.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,9 +133,11 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
*/
|
*/
|
||||||
public List<CcmRevision> retrieveRevisions(final T entity,
|
public List<CcmRevision> retrieveRevisions(final T entity,
|
||||||
final Long objectId) {
|
final Long objectId) {
|
||||||
|
|
||||||
final List<Number> revisionNumbers = retrieveRevisionNumbersOfEntity(
|
final List<Number> revisionNumbers = retrieveRevisionNumbersOfEntity(
|
||||||
entity, objectId);
|
entity, objectId);
|
||||||
|
|
||||||
|
final AuditReader auditReader = AuditReaderFactory.get(entityManager);
|
||||||
return revisionNumbers.stream()
|
return revisionNumbers.stream()
|
||||||
.map(revisionNumber -> auditReader.findRevision(CcmRevision.class,
|
.map(revisionNumber -> auditReader.findRevision(CcmRevision.class,
|
||||||
revisionNumber))
|
revisionNumber))
|
||||||
|
|
@ -142,19 +158,20 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
entity, objectId);
|
entity, objectId);
|
||||||
final Number lastRevision = revisions.get(revisions.size() - 1);
|
final Number lastRevision = revisions.get(revisions.size() - 1);
|
||||||
|
|
||||||
|
final AuditReader auditReader = AuditReaderFactory.get(entityManager);
|
||||||
return auditReader.findRevision(CcmRevision.class, lastRevision);
|
return auditReader.findRevision(CcmRevision.class, lastRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a specific revision object.
|
* Retrieves a specific revision object.
|
||||||
*
|
*
|
||||||
* @param entity
|
|
||||||
* @param objectId
|
|
||||||
* @param revision
|
* @param revision
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CcmRevision retrieveRevision(final Number revision) {
|
public CcmRevision retrieveRevision(final Number revision) {
|
||||||
|
|
||||||
|
final AuditReader auditReader = AuditReaderFactory.get(entityManager);
|
||||||
return auditReader.findRevision(CcmRevision.class, revision);
|
return auditReader.findRevision(CcmRevision.class, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue