Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/migrate-clarin-dspace5-to-clarin-dspace7-continue #220

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a0d995d
export table data as json
Paurikova2 Feb 1, 2023
0c03893
controller for group import
Paurikova2 Feb 5, 2023
14c780d
upgrade values type in database
Paurikova2 Feb 7, 2023
9db5f6a
alter table
Paurikova2 Feb 16, 2023
0c723ca
controller for group2group import
Paurikova2 Feb 17, 2023
05d18c2
controller for group2eperson
Paurikova2 Feb 20, 2023
8e07ae2
Removed varchar limitations (#218)
milanmajchrak Feb 24, 2023
5841e99
create new cntroller for item and service for workspaceitem
Paurikova2 Feb 28, 2023
62ca6f3
Merge branch 'internal/migrate-clarin-dspace5-to-clarin-dspace7' of g…
Paurikova2 Feb 28, 2023
8889e4a
changed Controller from ItemRest to WorkspaceRest
Paurikova2 Mar 1, 2023
e5a71ca
added test
Paurikova2 Mar 2, 2023
14f9138
fix error in controller
Paurikova2 Mar 3, 2023
88803df
create workflowitem from workspaceitem
Paurikova2 Mar 6, 2023
bf9d701
problem with adding submitter and creating workflowitem
Paurikova2 Mar 9, 2023
7153761
import workflowitem and item
Paurikova2 Mar 14, 2023
206aaf5
fix incorrect class in log'
Paurikova2 Mar 17, 2023
3942756
'reate bitstream without file, error with protected consturctor
Paurikova2 Mar 17, 2023
ea9c6ca
test for create bundle for existing file
Paurikova2 Mar 23, 2023
0ed2c9a
missing committed xml file
Paurikova2 Mar 24, 2023
924d718
fix errors for bitstream validation
Paurikova2 Mar 24, 2023
2b1a5d5
correction of the test errors
Paurikova2 Mar 29, 2023
ff8f24a
added primary bitstream to bitstream
Paurikova2 Mar 30, 2023
89e6831
test for import items
Paurikova2 Mar 31, 2023
2563c7e
Merge branch 'dtq-dev' into internal/migrate-clarin-dspace5-to-clarin…
Paurikova2 Mar 31, 2023
0c7be0b
fix item tests - inArchive
Paurikova2 Mar 31, 2023
cae6c28
fix import item tests
Paurikova2 Apr 5, 2023
8e3128a
correction of found errors
Paurikova2 Apr 14, 2023
5a828a5
controller for import eperson and user_registration
Paurikova2 Apr 14, 2023
4054a42
import logo of collection and community
Paurikova2 Apr 18, 2023
de11e72
modified bitstream import and added most_recent_checksum import
Paurikova2 Apr 20, 2023
e31d337
fix specifically date format
Paurikova2 Apr 20, 2023
f1d2821
added test for import logo
Paurikova2 Apr 20, 2023
405cf08
new builder for bitstream without item and bundle, fix test errors
Paurikova2 Apr 27, 2023
252d643
checkstyle and comments
Paurikova2 Apr 27, 2023
294dac7
fix tests
Paurikova2 Apr 28, 2023
20f9acd
checkstyle and fix test
Paurikova2 Apr 29, 2023
7a2c925
fix failed test
Paurikova2 Apr 29, 2023
36f070e
Merge branch 'dtq-dev' into internal/migrate-clarin-dspace5-to-clarin…
milanmajchrak May 1, 2023
79dc8a0
Fixed review issues.
May 1, 2023
fa6d4d5
74-BE license definition missing attribute values
Paurikova2 May 2, 2023
5fd2203
Merge branch 'internal/migrate-clarin-dspace5-to-clarin-dspace7-conti…
Paurikova2 May 2, 2023
b8190ba
Fixed review requests.
May 2, 2023
560b865
Removed unnecessary files
May 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Bitstream.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.clarin.ClarinBitstreamService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.hibernate.proxy.HibernateProxyHelper;
Expand Down Expand Up @@ -83,6 +84,8 @@ public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport
* {@link org.dspace.content.service.BitstreamService#create(Context, Bundle, InputStream)}
* or
* {@link org.dspace.content.service.BitstreamService#create(Context, InputStream)}
* or
* {@link ClarinBitstreamService#create(Context, Bundle)}
*/
protected Bitstream() {
}
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,31 @@ public Bitstream setLogo(Context context, Collection collection, InputStream is)
"collection_id=" + collection.getID()));
} else {
Bitstream newLogo = bitstreamService.create(context, is);
collection.setLogo(newLogo);

// now create policy for logo bitstream
// to match our READ policy
List<ResourcePolicy> policies = authorizeService
.getPoliciesActionFilter(context, collection, Constants.READ);
authorizeService.addPolicies(context, policies, newLogo);

log.info(LogHelper.getHeader(context, "set_logo",
"collection_id=" + collection.getID() + "logo_bitstream_id="
+ newLogo.getID()));
//added for data migration by Upgrade Dspace-Clarin
addLogo(context, collection, newLogo);
}

collection.setModified();
return collection.getLogo();
}

@Override
public void addLogo(Context context, Collection collection, Bitstream newLogo)
throws SQLException, AuthorizeException {
collection.setLogo(newLogo);

// now create policy for logo bitstream
// to match our READ policy
List<ResourcePolicy> policies = authorizeService
.getPoliciesActionFilter(context, collection, Constants.READ);
authorizeService.addPolicies(context, policies, newLogo);

log.info(LogHelper.getHeader(context, "set_logo",
"collection_id=" + collection.getID() + "logo_bitstream_id="
+ newLogo.getID()));
}

@Override
public Group createWorkflowGroup(Context context, Collection collection, int step)
throws SQLException, AuthorizeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public Community create(Community parent, Context context, String handle,
// of 'anonymous' READ
Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS);

authorizeService.createResourcePolicy(context, newCommunity, anonymousGroup, null, Constants.READ, null);
authorizeService.createResourcePolicy(context, newCommunity, anonymousGroup,null,
Constants.READ, null);

communityDAO.save(context, newCommunity);

Expand Down Expand Up @@ -237,22 +238,30 @@ public Bitstream setLogo(Context context, Community community, InputStream is)

if (is != null) {
Bitstream newLogo = bitstreamService.create(context, is);
community.setLogo(newLogo);

// now create policy for logo bitstream
// to match our READ policy
List<ResourcePolicy> policies = authorizeService
.getPoliciesActionFilter(context, community, Constants.READ);
authorizeService.addPolicies(context, policies, newLogo);

log.info(LogHelper.getHeader(context, "set_logo",
"community_id=" + community.getID() + "logo_bitstream_id="
+ newLogo.getID()));
//added for data migration by Upgrade Dspace-Clarin
addLogo(context, community, newLogo);
}

return community.getLogo();
}

@Override
public void addLogo(Context context, Community community, Bitstream newLogo)
throws SQLException, AuthorizeException {
community.setLogo(newLogo);

// now create policy for logo bitstream
// to match our READ policy
List<ResourcePolicy> policies = authorizeService
.getPoliciesActionFilter(context, community, Constants.READ);
authorizeService.addPolicies(context, policies, newLogo);

log.info(LogHelper.getHeader(context, "set_logo",
"community_id=" + community.getID() + "logo_bitstream_id="
+ newLogo.getID()));
}

@Override
public void update(Context context, Community community) throws SQLException, AuthorizeException {
// Check authorisation
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ public Collection create(Context context, Community community, String handle, UU
public Bitstream setLogo(Context context, Collection collection, InputStream is) throws AuthorizeException,
IOException, SQLException;

/**
* Add the created logo bitstream to collection and create policy to logo bitstream.
milanmajchrak marked this conversation as resolved.
Show resolved Hide resolved
* This method is added for data migration by Upgrade Clarin, where bitstream already exists.
* @param context context
* @param collection collection
* @param newLogo bitstream of new logo
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
*/
public void addLogo(Context context, Collection collection, Bitstream newLogo)
throws SQLException, AuthorizeException;
/**
* Create a workflow group for the given step if one does not already exist.
* Returns either the newly created group or the previously existing one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ public Community create(Community parent, Context context,
public Bitstream setLogo(Context context, Community community, InputStream is) throws AuthorizeException,
IOException, SQLException;

/**
* Add the created logo bitstream to community and create policy to logo bitstream.
* This method is added for data migration by Upgrade Clarin, where bitstream already exists.
* @param context context
* @param community community
* @param newLogo bitstream of new logo
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
*/
public void addLogo(Context context, Community community, Bitstream newLogo)
throws SQLException, AuthorizeException;
/**
* Create a default administrators group if one does not already exist.
* Returns either the newly created group or the previously existing one.
Expand Down
Loading