Table for Series
parent
96aee1917a
commit
6f5e33403a
|
|
@ -20,7 +20,6 @@ import com.arsdigita.bebop.table.TableColumnModel;
|
|||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
|
|
@ -28,7 +27,6 @@ import org.apache.logging.log4j.LogManager;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.assets.Person;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
import org.scientificcms.publications.Authorship;
|
||||
import org.scientificcms.publications.SciPublicationsConstants;
|
||||
|
|
@ -159,29 +157,6 @@ public class PublicationAuthorsTable
|
|||
addTableActionListener(this);
|
||||
}
|
||||
|
||||
private class PublicationAuthorsTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
private ItemSelectionModel itemModel;
|
||||
|
||||
public PublicationAuthorsTableModelBuilder(
|
||||
final ItemSelectionModel itemModel
|
||||
) {
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
|
||||
table.getRowSelectionModel().clearSelection(state);
|
||||
final PublicationItem<?> publication = (PublicationItem) itemModel
|
||||
.getSelectedObject(state);
|
||||
return new PublicationAuthorsTableModel(table, state, publication);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cellSelected(final TableActionEvent event)
|
||||
throws FormProcessException {
|
||||
|
|
@ -193,7 +168,8 @@ public class PublicationAuthorsTable
|
|||
.createCdiUtil()
|
||||
.findBean(SciPublicationsController.class);
|
||||
final Authorship authorship = controller.findAuthorship(
|
||||
selected.getPublication().getPublicationId(), event.getRowKey()
|
||||
selected.getPublication().getPublicationId(),
|
||||
event.getRowKey()
|
||||
).get();
|
||||
|
||||
final TableColumn column = getColumnModel().get(event.getColumn());
|
||||
|
|
@ -228,6 +204,29 @@ public class PublicationAuthorsTable
|
|||
// Nothing
|
||||
}
|
||||
|
||||
private class PublicationAuthorsTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
private ItemSelectionModel itemModel;
|
||||
|
||||
public PublicationAuthorsTableModelBuilder(
|
||||
final ItemSelectionModel itemModel
|
||||
) {
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
|
||||
table.getRowSelectionModel().clearSelection(state);
|
||||
final PublicationItem<?> publication = (PublicationItem) itemModel
|
||||
.getSelectedObject(state);
|
||||
return new PublicationAuthorsTableModel(table, state, publication);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class PublicationAuthorsTableModel implements TableModel {
|
||||
|
||||
private static final int MAX_DESC_LENGTH = 25;
|
||||
|
|
@ -260,9 +259,7 @@ public class PublicationAuthorsTable
|
|||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
|
||||
currentRow = iterator.next();
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class PublicationSeriesAddForm
|
|||
add(seriesSearchWidget);
|
||||
|
||||
final ParameterModel volumeOfSeriesParam = new StringParameter(
|
||||
SciPublicationsController.VOLUME_OF_SERIES
|
||||
SciPublicationsController.VOLUME_IN_SERIES
|
||||
);
|
||||
volumeOfSeries = new TextField(volumeOfSeriesParam);
|
||||
volumeOfSeries.setLabel(
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import org.scientificcms.publications.Authorship;
|
|||
import org.scientificcms.publications.Publication;
|
||||
import org.scientificcms.publications.PublicationManager;
|
||||
import org.scientificcms.publications.PublicationRepository;
|
||||
import org.scientificcms.publications.VolumeInSeries;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -60,7 +61,13 @@ class SciPublicationsController implements Serializable {
|
|||
|
||||
public static final String AUTHORSHIP_ORDER = "order";
|
||||
|
||||
public static final String VOLUME_OF_SERIES = "volumeOfSeries";
|
||||
public static final String VOLUME_IN_SERIES = "volumeInSeries";
|
||||
|
||||
public static final String VOLUME_IN_SERIES_ID = "volumeInSeriesId";
|
||||
|
||||
public static final String VOLUME_IN_SERIES_TITLE = "volumeInSeriesTitle";
|
||||
|
||||
public static final String VOLUME_IN_SERIES_VOLUME = "volumeInSeriesVolume";
|
||||
|
||||
@Inject
|
||||
private PersonRepository personRepository;
|
||||
|
|
@ -252,11 +259,8 @@ class SciPublicationsController implements Serializable {
|
|||
)
|
||||
);
|
||||
|
||||
final Optional<Authorship> authorship = publication
|
||||
.getAuthorships()
|
||||
.stream()
|
||||
.filter(current -> current.getAuthorshipId() == authorshipId)
|
||||
.findAny();
|
||||
final Optional<Authorship> authorship = findAuthorship(publicationId,
|
||||
authorshipId);
|
||||
|
||||
if (authorship.isPresent()) {
|
||||
publicationManager.removeAuthor(
|
||||
|
|
@ -372,6 +376,90 @@ class SciPublicationsController implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Map<String, Object>> getVolumesInSeries(
|
||||
final long publicationId
|
||||
) {
|
||||
final Publication publication = publicationRepository
|
||||
.findById(publicationId)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Publication with ID %d found.", publicationId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return publication
|
||||
.getSeries()
|
||||
.stream()
|
||||
.map(this::buildVolumeInSeriesEntry)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<String, Object> buildVolumeInSeriesEntry(
|
||||
final VolumeInSeries volumeInSeries
|
||||
) {
|
||||
Objects.requireNonNull(volumeInSeries);
|
||||
|
||||
final Map<String, Object> result = new HashMap<>();
|
||||
result.put(VOLUME_IN_SERIES_ID, volumeInSeries.getVolumeId());
|
||||
result.put(
|
||||
VOLUME_IN_SERIES_TITLE, volumeInSeries.getSeries().getTitle()
|
||||
);
|
||||
result.put(VOLUME_IN_SERIES_VOLUME, volumeInSeries.getVolumeOfSeries());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<VolumeInSeries> findVolumeInSeries(
|
||||
final long publicationId, final Object key
|
||||
) {
|
||||
final Publication publication = publicationRepository
|
||||
.findById(publicationId)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Publication with ID %d found.", publicationId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
final long volumeId = (long) key;
|
||||
|
||||
return publication
|
||||
.getSeries()
|
||||
.stream()
|
||||
.filter(series -> series.getVolumeId() == volumeId)
|
||||
.findAny();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void removeSeries(final long publicationId,
|
||||
final long volumeInSeriesId) {
|
||||
|
||||
final Publication publication = publicationRepository
|
||||
.findById(publicationId)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Publication with ID %d found.", publicationId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
final Optional<VolumeInSeries> volumeInSeries = findVolumeInSeries(
|
||||
publicationId, volumeInSeriesId);
|
||||
|
||||
if (volumeInSeries.isPresent()) {
|
||||
publicationManager.removeSeries(
|
||||
volumeInSeries.get().getSeries(),
|
||||
publication
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean filterAuthorship(final Authorship authorship,
|
||||
final Publication publication,
|
||||
final Person author) {
|
||||
|
|
|
|||
|
|
@ -324,10 +324,10 @@ public class PublicationManager {
|
|||
Objects.requireNonNull(publication);
|
||||
|
||||
final boolean alreadyAdded = publication
|
||||
.getSeries()
|
||||
.stream()
|
||||
.map(VolumeInSeries::getSeries)
|
||||
.anyMatch(obj -> obj.equals(series));
|
||||
.getSeries()
|
||||
.stream()
|
||||
.map(VolumeInSeries::getSeries)
|
||||
.anyMatch(obj -> obj.equals(series));
|
||||
|
||||
if (alreadyAdded) {
|
||||
throw new IllegalArgumentException(
|
||||
|
|
@ -349,4 +349,30 @@ public class PublicationManager {
|
|||
publicationRepository.save(publication);
|
||||
}
|
||||
|
||||
@AuthorizationRequired
|
||||
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void removeSeries(
|
||||
final Series series, final Publication fromPublication
|
||||
) {
|
||||
Objects.requireNonNull(series);
|
||||
Objects.requireNonNull(fromPublication);
|
||||
|
||||
final Optional<VolumeInSeries> result = fromPublication
|
||||
.getSeries()
|
||||
.stream()
|
||||
.filter(volume -> volume.getSeries().equals(series))
|
||||
.findAny();
|
||||
|
||||
if (!result.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final VolumeInSeries remove = result.get();
|
||||
fromPublication.removeSeries(remove);
|
||||
|
||||
entityManager.remove(remove);
|
||||
publicationRepository.save(fromPublication);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,10 +44,7 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
|||
),
|
||||
@NamedQuery(
|
||||
name = "Series.findByTitle",
|
||||
query = "SELECT DISTINCT s "
|
||||
+ "FROM Series s "
|
||||
+ "JOIN s.title.values t "
|
||||
+ "WHERE lower(t) LIKE CONCAT ('%', :title, '%')"
|
||||
query = "SELECT DISTINCT s FROM Series s JOIN s.title.values t WHERE lower(t) LIKE CONCAT ('%', :title, '%')"
|
||||
)
|
||||
})
|
||||
public class Series implements Serializable {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
package org.scientificcms.publications;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -25,6 +27,7 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name = "VOLUMES_IN_SERIES", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
public class VolumeInSeries implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
Loading…
Reference in New Issue