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.TableModel;
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
|
|
@ -28,7 +27,6 @@ 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.assets.Person;
|
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
import org.scientificcms.publications.Authorship;
|
import org.scientificcms.publications.Authorship;
|
||||||
import org.scientificcms.publications.SciPublicationsConstants;
|
import org.scientificcms.publications.SciPublicationsConstants;
|
||||||
|
|
@ -71,7 +69,7 @@ public class PublicationAuthorsTable
|
||||||
private final PublicationAuthorsPropertyStep editStep;
|
private final PublicationAuthorsPropertyStep editStep;
|
||||||
|
|
||||||
public PublicationAuthorsTable(
|
public PublicationAuthorsTable(
|
||||||
final ItemSelectionModel itemModel,
|
final ItemSelectionModel itemModel,
|
||||||
final PublicationAuthorsPropertyStep editStep
|
final PublicationAuthorsPropertyStep editStep
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -159,6 +157,53 @@ public class PublicationAuthorsTable
|
||||||
addTableActionListener(this);
|
addTableActionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cellSelected(final TableActionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final PublicationItem<?> selected = (PublicationItem<?>) itemModel
|
||||||
|
.getSelectedItem(state);
|
||||||
|
final SciPublicationsController controller = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(SciPublicationsController.class);
|
||||||
|
final Authorship authorship = controller.findAuthorship(
|
||||||
|
selected.getPublication().getPublicationId(),
|
||||||
|
event.getRowKey()
|
||||||
|
).get();
|
||||||
|
|
||||||
|
final TableColumn column = getColumnModel().get(event.getColumn());
|
||||||
|
|
||||||
|
if (TABLE_COL_EDIT_ASSOC.equals(column.getHeaderKey())) {
|
||||||
|
editStep.setSelectedAuthor(authorship.getAuthor());
|
||||||
|
editStep.setSelectedAuthorEditor(authorship.isEditor());
|
||||||
|
|
||||||
|
editStep.showComponent(state, "AuthorsEntryForm");
|
||||||
|
} else if (TABLE_COL_DEL.equals(column.getHeaderKey())) {
|
||||||
|
controller.removeAuthor(
|
||||||
|
selected.getPublication().getPublicationId(),
|
||||||
|
authorship.getAuthorshipId()
|
||||||
|
);
|
||||||
|
} else if (TABLE_COL_UP.equals(column.getHeaderKey())) {
|
||||||
|
controller.swapWithPrevAuthorship(
|
||||||
|
selected.getPublication().getPublicationId(),
|
||||||
|
authorship.getAuthorshipId()
|
||||||
|
);
|
||||||
|
} else if (TABLE_COL_DOWN.equals(column.getHeaderKey())) {
|
||||||
|
controller.swapWithNextAuthorship(
|
||||||
|
selected.getPublication().getPublicationId(),
|
||||||
|
authorship.getAuthorshipId()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void headSelected(final TableActionEvent event) {
|
||||||
|
|
||||||
|
// Nothing
|
||||||
|
}
|
||||||
|
|
||||||
private class PublicationAuthorsTableModelBuilder
|
private class PublicationAuthorsTableModelBuilder
|
||||||
extends LockableImpl
|
extends LockableImpl
|
||||||
implements TableModelBuilder {
|
implements TableModelBuilder {
|
||||||
|
|
@ -182,52 +227,6 @@ public class PublicationAuthorsTable
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final PublicationItem<?> selected = (PublicationItem<?>) itemModel
|
|
||||||
.getSelectedItem(state);
|
|
||||||
final SciPublicationsController controller = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(SciPublicationsController.class);
|
|
||||||
final Authorship authorship = controller.findAuthorship(
|
|
||||||
selected.getPublication().getPublicationId(), event.getRowKey()
|
|
||||||
).get();
|
|
||||||
|
|
||||||
final TableColumn column = getColumnModel().get(event.getColumn());
|
|
||||||
|
|
||||||
if (TABLE_COL_EDIT_ASSOC.equals(column.getHeaderKey())) {
|
|
||||||
editStep.setSelectedAuthor(authorship.getAuthor());
|
|
||||||
editStep.setSelectedAuthorEditor(authorship.isEditor());
|
|
||||||
|
|
||||||
editStep.showComponent(state, "AuthorsEntryForm");
|
|
||||||
} else if (TABLE_COL_DEL.equals(column.getHeaderKey())) {
|
|
||||||
controller.removeAuthor(
|
|
||||||
selected.getPublication().getPublicationId(),
|
|
||||||
authorship.getAuthorshipId()
|
|
||||||
);
|
|
||||||
} else if (TABLE_COL_UP.equals(column.getHeaderKey())) {
|
|
||||||
controller.swapWithPrevAuthorship(
|
|
||||||
selected.getPublication().getPublicationId(),
|
|
||||||
authorship.getAuthorshipId()
|
|
||||||
);
|
|
||||||
} else if (TABLE_COL_DOWN.equals(column.getHeaderKey())) {
|
|
||||||
controller.swapWithNextAuthorship(
|
|
||||||
selected.getPublication().getPublicationId(),
|
|
||||||
authorship.getAuthorshipId()
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
|
|
||||||
// Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PublicationAuthorsTableModel implements TableModel {
|
private class PublicationAuthorsTableModel implements TableModel {
|
||||||
|
|
||||||
private static final int MAX_DESC_LENGTH = 25;
|
private static final int MAX_DESC_LENGTH = 25;
|
||||||
|
|
@ -260,9 +259,7 @@ public class PublicationAuthorsTable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean nextRow() {
|
public boolean nextRow() {
|
||||||
|
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
|
|
||||||
currentRow = iterator.next();
|
currentRow = iterator.next();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ public class PublicationSeriesAddForm
|
||||||
add(seriesSearchWidget);
|
add(seriesSearchWidget);
|
||||||
|
|
||||||
final ParameterModel volumeOfSeriesParam = new StringParameter(
|
final ParameterModel volumeOfSeriesParam = new StringParameter(
|
||||||
SciPublicationsController.VOLUME_OF_SERIES
|
SciPublicationsController.VOLUME_IN_SERIES
|
||||||
);
|
);
|
||||||
volumeOfSeries = new TextField(volumeOfSeriesParam);
|
volumeOfSeries = new TextField(volumeOfSeriesParam);
|
||||||
volumeOfSeries.setLabel(
|
volumeOfSeries.setLabel(
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.scientificcms.publications.Authorship;
|
||||||
import org.scientificcms.publications.Publication;
|
import org.scientificcms.publications.Publication;
|
||||||
import org.scientificcms.publications.PublicationManager;
|
import org.scientificcms.publications.PublicationManager;
|
||||||
import org.scientificcms.publications.PublicationRepository;
|
import org.scientificcms.publications.PublicationRepository;
|
||||||
|
import org.scientificcms.publications.VolumeInSeries;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -59,8 +60,14 @@ class SciPublicationsController implements Serializable {
|
||||||
public static final String AUTHORSHIP_IS_EDITOR = "isEditor";
|
public static final String AUTHORSHIP_IS_EDITOR = "isEditor";
|
||||||
|
|
||||||
public static final String AUTHORSHIP_ORDER = "order";
|
public static final String AUTHORSHIP_ORDER = "order";
|
||||||
|
|
||||||
|
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_OF_SERIES = "volumeOfSeries";
|
public static final String VOLUME_IN_SERIES_VOLUME = "volumeInSeriesVolume";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PersonRepository personRepository;
|
private PersonRepository personRepository;
|
||||||
|
|
@ -252,11 +259,8 @@ class SciPublicationsController implements Serializable {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
final Optional<Authorship> authorship = publication
|
final Optional<Authorship> authorship = findAuthorship(publicationId,
|
||||||
.getAuthorships()
|
authorshipId);
|
||||||
.stream()
|
|
||||||
.filter(current -> current.getAuthorshipId() == authorshipId)
|
|
||||||
.findAny();
|
|
||||||
|
|
||||||
if (authorship.isPresent()) {
|
if (authorship.isPresent()) {
|
||||||
publicationManager.removeAuthor(
|
publicationManager.removeAuthor(
|
||||||
|
|
@ -352,26 +356,110 @@ class SciPublicationsController implements Serializable {
|
||||||
Authorship authorship = null;
|
Authorship authorship = null;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
for (int i = 0; i < authorships.size(); i++) {
|
for (int i = 0; i < authorships.size(); i++) {
|
||||||
|
|
||||||
if (authorships.get(i).getAuthorshipId() == authorshipId) {
|
if (authorships.get(i).getAuthorshipId() == authorshipId) {
|
||||||
authorship = authorships.get(i);
|
authorship = authorships.get(i);
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index < authorships.size() && authorship != null) {
|
if (index < authorships.size() && authorship != null) {
|
||||||
final long order = authorship.getAuthorOrder();
|
final long order = authorship.getAuthorOrder();
|
||||||
final Authorship nextAuthorship = authorships.get(index + 1);
|
final Authorship nextAuthorship = authorships.get(index + 1);
|
||||||
final long nextOrder = nextAuthorship.getAuthorOrder();
|
final long nextOrder = nextAuthorship.getAuthorOrder();
|
||||||
|
|
||||||
authorship.setAuthorOrder(nextOrder);
|
authorship.setAuthorOrder(nextOrder);
|
||||||
nextAuthorship.setAuthorOrder(order);
|
nextAuthorship.setAuthorOrder(order);
|
||||||
|
|
||||||
publicationRepository.save(publication);
|
publicationRepository.save(publication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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,
|
private boolean filterAuthorship(final Authorship authorship,
|
||||||
final Publication publication,
|
final Publication publication,
|
||||||
final Person author) {
|
final Person author) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public class PublicationManager {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PublicationRepository publicationRepository;
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
|
@ -322,13 +322,13 @@ public class PublicationManager {
|
||||||
) {
|
) {
|
||||||
Objects.requireNonNull(series);
|
Objects.requireNonNull(series);
|
||||||
Objects.requireNonNull(publication);
|
Objects.requireNonNull(publication);
|
||||||
|
|
||||||
final boolean alreadyAdded = publication
|
final boolean alreadyAdded = publication
|
||||||
.getSeries()
|
.getSeries()
|
||||||
.stream()
|
.stream()
|
||||||
.map(VolumeInSeries::getSeries)
|
.map(VolumeInSeries::getSeries)
|
||||||
.anyMatch(obj -> obj.equals(series));
|
.anyMatch(obj -> obj.equals(series));
|
||||||
|
|
||||||
if (alreadyAdded) {
|
if (alreadyAdded) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
|
|
@ -338,7 +338,7 @@ public class PublicationManager {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final VolumeInSeries volume = new VolumeInSeries();
|
final VolumeInSeries volume = new VolumeInSeries();
|
||||||
volume.setPublication(publication);
|
volume.setPublication(publication);
|
||||||
volume.setSeries(series);
|
volume.setSeries(series);
|
||||||
|
|
@ -349,4 +349,30 @@ public class PublicationManager {
|
||||||
publicationRepository.save(publication);
|
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(
|
@NamedQuery(
|
||||||
name = "Series.findByTitle",
|
name = "Series.findByTitle",
|
||||||
query = "SELECT DISTINCT s "
|
query = "SELECT DISTINCT s FROM Series s JOIN s.title.values t WHERE lower(t) LIKE CONCAT ('%', :title, '%')"
|
||||||
+ "FROM Series s "
|
|
||||||
+ "JOIN s.title.values t "
|
|
||||||
+ "WHERE lower(t) LIKE CONCAT ('%', :title, '%')"
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
public class Series implements Serializable {
|
public class Series implements Serializable {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
*/
|
*/
|
||||||
package org.scientificcms.publications;
|
package org.scientificcms.publications;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -25,6 +27,7 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "VOLUMES_IN_SERIES", schema = DB_SCHEMA)
|
@Table(name = "VOLUMES_IN_SERIES", schema = DB_SCHEMA)
|
||||||
|
@Audited
|
||||||
public class VolumeInSeries implements Serializable {
|
public class VolumeInSeries implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue