Skip to content

Commit

Permalink
Merged in DSC-1632 (pull request DSpace#2015)
Browse files Browse the repository at this point in the history
DSC-1632
  • Loading branch information
steph-ieffam committed Apr 15, 2024
2 parents 2b91e9a + 785f743 commit 0880245
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public enum CrisLayoutBoxTypes {
METADATA,
RELATION,
METRICS,
COLLECTIONS
COLLECTIONS,
VERSIONING
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.dspace.layout.service.CrisLayoutBoxAccessService;
import org.dspace.layout.service.CrisLayoutBoxService;
import org.dspace.metrics.CrisItemMetricsService;
import org.dspace.versioning.service.VersionHistoryService;
import org.springframework.beans.factory.annotation.Autowired;

/**
Expand Down Expand Up @@ -71,6 +72,9 @@ public class CrisLayoutBoxServiceImpl implements CrisLayoutBoxService {
@Autowired
private BitstreamService bitstreamService;

@Autowired
private VersionHistoryService versionHistoryService;

public CrisLayoutBoxServiceImpl() {
}

Expand Down Expand Up @@ -164,13 +168,22 @@ public boolean hasContent(Context context, CrisLayoutBox box, Item item) {
return isOwningCollectionPresent(item);
case "IIIFVIEWER":
return isIiifEnabled(item);
case "VERSIONING":
return hasVersioningBox(context, item);
case "METADATA":
default:
return hasMetadataBoxContent(context, box, item);
}

}

private boolean hasVersioningBox(Context context, Item item) {
try {
return versionHistoryService.hasVersionHistory(context, item);
} catch (SQLException e) {
return false;
}
}
@Override
public boolean hasAccess(Context context, CrisLayoutBox box, Item item) {
return crisLayoutBoxAccessService.hasAccess(context, context.getCurrentUser(), box, item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.layout.CrisLayoutBox;
import org.dspace.layout.CrisLayoutBoxTypes;
import org.dspace.layout.service.impl.CrisLayoutBoxServiceImpl;
import org.dspace.versioning.service.VersioningService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Unit tests for CrisLayoutBoxServiceImpl, so far only findByItem method is
* tested.
*
* @author Corrado Lombardi (corrado.lombardi at 4science.it)
*/

public class CrisLayoutBoxServiceImplIT extends AbstractControllerIntegrationTest {

@Autowired
private CrisLayoutBoxServiceImpl crisLayoutBoxService;

@Autowired
private VersioningService versioningService;

@Test
public void testHasContentVersioningBox() {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context).build();
Collection col = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Test collection")
.build();

Item item = ItemBuilder
.createItem(context, col)
.withTitle("test")
.build();

versioningService.createNewVersion(context, item);

CrisLayoutBox box = crisLayoutVersioningBox("versioning");

assertThat(crisLayoutBoxService.hasContent(context, box, item), is(true));
context.restoreAuthSystemState();
}

@Test
public void testHasNoContentVersioningBox() {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context).build();
Collection col = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Test collection")
.build();

Item item = ItemBuilder
.createItem(context, col)
.withTitle("test")
.build();

CrisLayoutBox box = crisLayoutVersioningBox("versioning");

assertThat(crisLayoutBoxService.hasContent(context, box, item), is(false));
context.restoreAuthSystemState();
}

private CrisLayoutBox crisLayoutVersioningBox(String shortname) {
return crisLayoutBox(shortname, CrisLayoutBoxTypes.VERSIONING.name());
}

private CrisLayoutBox crisLayoutBox(String shortname, String boxType) {
CrisLayoutBox box = new CrisLayoutBox();
box.setShortname(shortname);
box.setType(boxType);
return box;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;

import java.util.List;

Expand All @@ -38,6 +39,7 @@
import org.dspace.content.service.MetadataFieldService;
import org.dspace.content.service.MetadataSchemaService;
import org.dspace.layout.CrisLayoutBox;
import org.dspace.layout.CrisLayoutBoxTypes;
import org.dspace.layout.CrisLayoutField;
import org.dspace.layout.LayoutSecurity;
import org.junit.Test;
Expand Down Expand Up @@ -312,4 +314,43 @@ public void testMetricsBoxConversion() throws Exception {
assertThat(config.getMaxColumns(), is(1));
assertThat(config.getMetrics(), contains("metric1", "metric2"));
}

@Test
public void testVersioningBoxConversion() throws Exception {

context.turnOffAuthorisationSystem();

EntityType entityType = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication").build();

CrisLayoutBox box = CrisLayoutBoxBuilder.createBuilder(context, entityType, true, true)
.withContainer(true)
.withHeader("Box Header")
.withShortname("versioning")
.withType(CrisLayoutBoxTypes.VERSIONING.name())
.withSecurity(LayoutSecurity.OWNER_ONLY)
.withMaxColumns(1)
.build();

CrisLayoutMetric2BoxBuilder.create(context, box, "metric1", 0).build();
CrisLayoutMetric2BoxBuilder.create(context, box, "metric2", 1).build();

context.commit();

context.restoreAuthSystemState();

CrisLayoutBoxRest rest = converter.convert(box, Projection.DEFAULT);
assertThat(rest, notNullValue());
assertThat(rest.getBoxType(), is(CrisLayoutBoxTypes.VERSIONING.name()));
assertThat(rest.isContainer(), is(true));
assertThat(rest.getCollapsed(), is(true));
assertThat(rest.getEntityType(), is("Publication"));
assertThat(rest.getHeader(), is("Box Header"));
assertThat(rest.getShortname(), is("versioning"));
assertThat(rest.getMaxColumns(), is(1));
assertThat(rest.getMinor(), is(true));
assertThat(rest.getSecurity(), is(2));
assertThat(rest.getStyle(), nullValue());
assertThat(rest.getMetadataSecurityFields(), empty());
assertEquals(rest.getConfiguration(), null);
}
}
Binary file modified dspace/etc/conftool/cris-layout-configuration.xls
Binary file not shown.

0 comments on commit 0880245

Please sign in to comment.