forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/migrate-clarin-dspace5-to-clarin-dspace7-continue (#220)
* export table data as json * controller for group import * upgrade values type in database * alter table * controller for group2group import * controller for group2eperson * Removed varchar limitations (#218) Co-authored-by: MilanMajchrák <milan.majchak@dataquest.sk> * create new cntroller for item and service for workspaceitem * changed Controller from ItemRest to WorkspaceRest * added test * fix error in controller * create workflowitem from workspaceitem * problem with adding submitter and creating workflowitem * import workflowitem and item * fix incorrect class in log' * 'reate bitstream without file, error with protected consturctor * test for create bundle for existing file * missing committed xml file * fix errors for bitstream validation * correction of the test errors * added primary bitstream to bitstream * test for import items * fix item tests - inArchive * fix import item tests * correction of found errors * controller for import eperson and user_registration * import logo of collection and community * modified bitstream import and added most_recent_checksum import * fix specifically date format * added test for import logo * new builder for bitstream without item and bundle, fix test errors * checkstyle and comments * fix tests * checkstyle and fix test * fix failed test * Fixed review issues. * 74-BE license definition missing attribute values * Fixed review requests. * Removed unnecessary files --------- Co-authored-by: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Co-authored-by: MilanMajchrák <milan.majchak@dataquest.sk>
- Loading branch information
1 parent
6b58fa8
commit 63c9de3
Showing
28 changed files
with
2,576 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
dspace-api/src/main/java/org/dspace/content/ClarinBitstreamServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* 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.content; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.Objects; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.Logger; | ||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.service.AuthorizeService; | ||
import org.dspace.content.dao.BitstreamDAO; | ||
import org.dspace.content.service.BitstreamService; | ||
import org.dspace.content.service.BundleService; | ||
import org.dspace.content.service.clarin.ClarinBitstreamService; | ||
import org.dspace.core.Constants; | ||
import org.dspace.core.Context; | ||
import org.dspace.event.Event; | ||
import org.dspace.storage.bitstore.DSBitStoreService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Service interface class for the Bitstream object created for Clarin-Dspace import. | ||
* Contains methods needed to import bitstream when dspace5 migrating to dspace7. | ||
* The implementation of this class is autowired by spring. | ||
* This class should never be accessed directly. | ||
* | ||
* @author Michaela Paurikova (michaela.paurikova at dataquest.sk) | ||
*/ | ||
//If this class wants to catch the Bitstream protected constructor, it must be in this package! | ||
public class ClarinBitstreamServiceImpl implements ClarinBitstreamService { | ||
/** | ||
* log4j logger | ||
*/ | ||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(ClarinBitstreamServiceImpl.class); | ||
|
||
// Checksum algorithm | ||
private static final String CSA = "MD5"; | ||
|
||
@Autowired | ||
private DSBitStoreService storeService; | ||
@Autowired | ||
protected BitstreamDAO bitstreamDAO; | ||
@Autowired | ||
protected AuthorizeService authorizeService; | ||
@Autowired | ||
protected BundleService bundleService; | ||
@Autowired | ||
protected BitstreamService bitstreamService; | ||
|
||
protected ClarinBitstreamServiceImpl() { | ||
} | ||
|
||
@Override | ||
public Bitstream create(Context context, Bundle bundle) throws SQLException, AuthorizeException { | ||
if (!authorizeService.isAdmin(context)) { | ||
throw new AuthorizeException( | ||
"You must be an admin to create an empty bitstream"); | ||
} | ||
//create empty bitstream | ||
Bitstream bitstream = bitstreamDAO.create(context, new Bitstream()); | ||
|
||
// Set the format to "unknown" | ||
bitstreamService.setFormat(context, bitstream, null); | ||
context.addEvent( | ||
new Event(Event.CREATE, Constants.BITSTREAM, bitstream.getID(), | ||
null, bitstreamService.getIdentifiers(context, bitstream))); | ||
|
||
//add bitstream to bundle if the bundle is entered | ||
if (Objects.nonNull(bundle)) { | ||
bundleService.addBitstream(context, bundle, bitstream); | ||
} | ||
log.debug("Created new empty Bitstream with id: " + bitstream.getID()); | ||
return bitstream; | ||
} | ||
|
||
@Override | ||
public boolean addExistingFile(Context context, Bitstream bitstream, Long expectedSizeBytes, | ||
String expectedCheckSum, String expectedChecksumAlgorithm) | ||
throws IOException, SQLException, AuthorizeException { | ||
if (!authorizeService.isAdmin(context)) { | ||
throw new AuthorizeException( | ||
"You must be an admin to add existing file to bitstream"); | ||
} | ||
if (Objects.isNull(bitstream) || StringUtils.isBlank(bitstream.getInternalId())) { | ||
throw new IllegalStateException( | ||
"Cannot add file to bitstream because it is entered incorrectly."); | ||
} | ||
//get file from assetstore based on internal_id | ||
//recalculate check fields | ||
storeService.put(bitstream, new ByteArrayInputStream(storeService.get(bitstream).readAllBytes())); | ||
//check that new calculated values match the expected values | ||
if (!valid(bitstream, expectedSizeBytes, expectedCheckSum, expectedChecksumAlgorithm)) { | ||
//an error occurred - expected and calculated values do not match | ||
//delete all created data | ||
bitstreamService.delete(context, bitstream); | ||
bitstreamService.expunge(context, bitstream); | ||
log.debug("Cannot add file with internal id: " + | ||
bitstream.getInternalId() + " to bitstream with id: " + bitstream.getID() | ||
+ " because the validation is incorrectly."); | ||
return false; | ||
} | ||
bitstreamService.update(context, bitstream); | ||
return true; | ||
} | ||
|
||
/** | ||
* Validation control. | ||
* Control that expected values (method attributes) match with bitstream calculated values. | ||
* @param bitstream bitstream | ||
* @param expectedSizeBytes expected size bytes | ||
* @param expectedCheckSum expected checksum | ||
* @param expectedChecksumAlgorithm expected checksum algorithm | ||
* @return bitstream values match with expected values | ||
*/ | ||
private boolean valid(Bitstream bitstream, long expectedSizeBytes, | ||
String expectedCheckSum, String expectedChecksumAlgorithm) { | ||
return bitstream.getSizeBytes() == expectedSizeBytes && bitstream.getChecksum().equals(expectedCheckSum) && | ||
bitstream.getChecksumAlgorithm().equals(expectedChecksumAlgorithm); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
dspace-api/src/main/java/org/dspace/content/clarin/ClarinWorkspaceItemServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* 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.content.clarin; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.content.Collection; | ||
import org.dspace.content.WorkspaceItem; | ||
import org.dspace.content.dao.WorkspaceItemDAO; | ||
import org.dspace.content.service.WorkspaceItemService; | ||
import org.dspace.content.service.clarin.ClarinWorkspaceItemService; | ||
import org.dspace.core.Context; | ||
import org.dspace.core.LogHelper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Service interface class for the WorkspaceItem object created for Clarin-Dspace import. | ||
* Contains methods needed to import bitstream when dspace5 migrating to dspace7. | ||
* The implementation of this class is autowired by spring. | ||
* This class should never be accessed directly. | ||
* | ||
* @author Michaela Paurikova(michaela.paurikova at dataquest.sk) | ||
*/ | ||
public class ClarinWorkspaceItemServiceImpl implements ClarinWorkspaceItemService { | ||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger( | ||
ClarinWorkspaceItemServiceImpl.class); | ||
@Autowired | ||
private WorkspaceItemService workspaceItemService; | ||
@Autowired | ||
private WorkspaceItemDAO workspaceItemDAO; | ||
|
||
@Override | ||
public WorkspaceItem create(Context context, Collection collection, boolean multipleTitles, boolean publishedBefore, | ||
boolean multipleFiles, Integer stageReached, Integer pageReached, | ||
boolean template) throws AuthorizeException, SQLException { | ||
|
||
//create empty workspace item with item | ||
WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false); | ||
//set workspace item values based on input values | ||
workspaceItem.setPublishedBefore(publishedBefore); | ||
workspaceItem.setMultipleFiles(multipleFiles); | ||
workspaceItem.setMultipleTitles(multipleTitles); | ||
workspaceItem.setPageReached(pageReached); | ||
workspaceItem.setStageReached(stageReached); | ||
return workspaceItem; | ||
} | ||
|
||
@Override | ||
public WorkspaceItem find(Context context, UUID uuid) throws SQLException { | ||
//find workspace item by its UUID | ||
WorkspaceItem workspaceItem = workspaceItemDAO.findByID(context, WorkspaceItem.class, uuid); | ||
|
||
//create log if the workspace item is not found | ||
if (log.isDebugEnabled()) { | ||
if (Objects.nonNull(workspaceItem)) { | ||
log.debug(LogHelper.getHeader(context, "find_workspace_item", | ||
"not_found,workspace_item_uuid=" + uuid)); | ||
} else { | ||
log.debug(LogHelper.getHeader(context, "find_workspace_item", | ||
"workspace_item_uuid=" + uuid)); | ||
} | ||
} | ||
return workspaceItem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.