mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 05:23:14 +00:00
w2p-80200 Add new tests for each dspace object, cleaned up java docs and authrorization inside of create
This commit is contained in:
@@ -104,6 +104,13 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
protected Collection() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a pre-determined UUID to be passed to the object to allow for the
|
||||
* restoration of previously defined UUID's.
|
||||
*
|
||||
* @param uuid Takes a uuid to be passed to the Pre-Defined UUID Generator
|
||||
*/
|
||||
protected Collection(UUID uuid) {
|
||||
this.predefinedUUID = uuid;
|
||||
}
|
||||
|
@@ -97,6 +97,12 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a pre-determined UUID to be passed to the object to allow for the
|
||||
* restoration of previously defined UUID's.
|
||||
*
|
||||
* @param uuid Takes a uuid to be passed to the Pre-Defined UUID Generator
|
||||
*/
|
||||
protected Community(UUID uuid) {
|
||||
this.predefinedUUID = uuid;
|
||||
}
|
||||
|
@@ -38,8 +38,8 @@ import org.hibernate.annotations.GenericGenerator;
|
||||
@Table(name = "dspaceobject")
|
||||
public abstract class DSpaceObject implements Serializable, ReloadableEntity<java.util.UUID> {
|
||||
@Id
|
||||
@GeneratedValue(generator = "check-existing-uuid")
|
||||
@GenericGenerator(name = "check-existing-uuid", strategy = "org.dspace.content.CheckExistingUUIDGenerator")
|
||||
@GeneratedValue(generator = "predefined-uuid")
|
||||
@GenericGenerator(name = "predefined-uuid", strategy = "org.dspace.content.PredefinedUUIDGenerator")
|
||||
@Column(name = "uuid", unique = true, nullable = false, insertable = true, updatable = false)
|
||||
protected java.util.UUID id;
|
||||
|
||||
@@ -76,6 +76,9 @@ public abstract class DSpaceObject implements Serializable, ReloadableEntity<jav
|
||||
@Transient
|
||||
private boolean modified = false;
|
||||
|
||||
/**
|
||||
* This will read our predefinedUUID property to pass it along to the UUID generator
|
||||
*/
|
||||
@Transient
|
||||
protected UUID predefinedUUID;
|
||||
public UUID getPredefinedUUID() {
|
||||
|
@@ -132,6 +132,12 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a pre-determined UUID to be passed to the object to allow for the
|
||||
* restoration of previously defined UUID's.
|
||||
*
|
||||
* @param uuid Takes a uuid to be passed to the Pre-Defined UUID Generator
|
||||
*/
|
||||
protected Item(UUID uuid) {
|
||||
this.predefinedUUID = uuid;
|
||||
}
|
||||
|
@@ -176,6 +176,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
|
||||
@Override
|
||||
public Item create(Context context, WorkspaceItem workspaceItem) throws SQLException, AuthorizeException {
|
||||
authorizeService.authorizeAction(context, workspaceItem.getCollection(), Constants.ADD);
|
||||
if (workspaceItem.getItem() != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Attempting to create an item for a workspace item that already contains an item");
|
||||
@@ -193,6 +194,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
@Override
|
||||
public Item create(Context context, WorkspaceItem workspaceItem,
|
||||
UUID uuid) throws SQLException, AuthorizeException {
|
||||
authorizeService.authorizeAction(context, workspaceItem.getCollection(), Constants.ADD);
|
||||
if (workspaceItem.getItem() != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Attempting to create an item for a workspace item that already contains an item");
|
||||
|
@@ -18,7 +18,7 @@ import org.hibernate.id.UUIDGenerator;
|
||||
*
|
||||
* @author April Herron
|
||||
*/
|
||||
public class CheckExistingUUIDGenerator extends UUIDGenerator {
|
||||
public class PredefinedUUIDGenerator extends UUIDGenerator {
|
||||
|
||||
@Override
|
||||
public Serializable generate(SharedSessionContractImplementor session, Object object) {
|
@@ -43,9 +43,8 @@ public interface ItemService
|
||||
public Thumbnail getThumbnail(Context context, Item item, boolean requireOriginal) throws SQLException;
|
||||
|
||||
/**
|
||||
* Create a new item, with a new internal ID. This method is not public,
|
||||
* since items need to be created as workspace items. Authorisation is the
|
||||
* responsibility of the caller.
|
||||
* Create a new item, with a new internal ID. Authorization is done
|
||||
* inside of this method.
|
||||
*
|
||||
* @param context DSpace context object
|
||||
* @param workspaceItem in progress workspace item
|
||||
@@ -56,9 +55,8 @@ public interface ItemService
|
||||
public Item create(Context context, WorkspaceItem workspaceItem) throws SQLException, AuthorizeException;
|
||||
|
||||
/**
|
||||
* Create a new item, with a provided ID. This method is not public,
|
||||
* since items need to be created as workspace items. Authorisation is the
|
||||
* responsibility of the caller.
|
||||
* Create a new item, with a provided ID. Authorisation is done
|
||||
* inside of this method.
|
||||
*
|
||||
* @param context DSpace context object
|
||||
* @param workspaceItem in progress workspace item
|
||||
|
@@ -13,10 +13,12 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import org.dspace.AbstractIntegrationTestWithDatabase;
|
||||
import org.dspace.builder.CollectionBuilder;
|
||||
import org.dspace.builder.CommunityBuilder;
|
||||
@@ -27,13 +29,20 @@ import org.dspace.content.Item;
|
||||
import org.dspace.content.crosswalk.MetadataValidationException;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.packager.METSManifest;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.jdom.Element;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PackagerIT extends AbstractIntegrationTestWithDatabase {
|
||||
|
||||
private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||
private CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||
protected ConfigurationService configService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
protected Community child1;
|
||||
protected Collection col1;
|
||||
protected Item article;
|
||||
@@ -60,6 +69,7 @@ public class PackagerIT extends AbstractIntegrationTestWithDatabase {
|
||||
createTemplate();
|
||||
createFiles();
|
||||
try {
|
||||
//Item
|
||||
performExportScript(article.getHandle(), tempFile);
|
||||
String idStr = getID();
|
||||
itemService.delete(context, article);
|
||||
@@ -71,6 +81,59 @@ public class PackagerIT extends AbstractIntegrationTestWithDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packagerImportColUUIDTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
createTemplate();
|
||||
createFiles();
|
||||
configService.setProperty("upload.temp.dir",tempFile.getParent());
|
||||
try {
|
||||
performExportScript(col1.getHandle(), tempFile);
|
||||
String idStr = getID();
|
||||
collectionService.delete(context, col1);
|
||||
performImportScript(tempFile);
|
||||
Collection collection = collectionService.find(context, UUID.fromString(idStr));
|
||||
assertNotNull(collection);
|
||||
} finally {
|
||||
tempFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packagerImportComUUIDTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
createTemplate();
|
||||
createFiles();
|
||||
configService.setProperty("upload.temp.dir",tempFile.getParent());
|
||||
try {
|
||||
//Community
|
||||
performExportScript(child1.getHandle(), tempFile);
|
||||
String idStr = getID();
|
||||
communityService.delete(context, child1);
|
||||
performImportScript(tempFile);
|
||||
Community community = communityService.find(context, UUID.fromString(idStr));
|
||||
assertNotNull(community);
|
||||
} finally {
|
||||
tempFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packagerUUIDAlreadyExistTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
createTemplate();
|
||||
createFiles();
|
||||
try {
|
||||
//Item should be overwritten if UUID already Exists
|
||||
performExportScript(article.getHandle(), tempFile);
|
||||
performImportScript(tempFile);
|
||||
Iterator<Item> items = itemService.findByCollection(context, col1);
|
||||
assertEquals(1, Iterators.size(items));
|
||||
} finally {
|
||||
tempFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
protected void createTemplate() {
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
|
1
dspace/modules/dspace-replicate
Submodule
1
dspace/modules/dspace-replicate
Submodule
Submodule dspace/modules/dspace-replicate added at 5c19e3e515
Reference in New Issue
Block a user