Skip to content

Commit

Permalink
make object from provenance service
Browse files Browse the repository at this point in the history
  • Loading branch information
Paurikova2 committed Nov 22, 2024
1 parent 64d7eae commit 49cae22
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.ProvenanceService;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.ProvenanceProvider;
import org.dspace.discovery.DiscoverQuery;
import org.dspace.discovery.SearchService;
import org.dspace.discovery.SearchServiceException;
Expand Down Expand Up @@ -113,7 +112,7 @@ public class BulkAccessControl extends DSpaceRunnable<BulkAccessControlScriptCon

protected String eperson = null;

protected ProvenanceService provenanceService;
protected ProvenanceProvider provenanceProvider = new ProvenanceProvider();

@Override
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -147,7 +146,6 @@ public void setup() throws ParseException {
help = commandLine.hasOption('h');
filename = commandLine.getOptionValue('f');
uuids = commandLine.hasOption('u') ? Arrays.asList(commandLine.getOptionValues('u')) : null;
this.provenanceService = CoreServiceFactory.getInstance().getProvenanceService();
}

@Override
Expand Down Expand Up @@ -471,7 +469,7 @@ private void setItemPolicies(Item item, BulkAccessControlInput accessControl)

itemService.adjustItemPolicies(context, item, item.getOwningCollection(), false);

provenanceService.setItemPolicies(context, item, accessControl);
provenanceProvider.setItemPolicies(context, item, accessControl);
}

/**
Expand Down Expand Up @@ -559,7 +557,7 @@ private void updateBitstreamPolicies(Bitstream bitstream, Item item, BulkAccessC
*/
private void removeReadPolicies(DSpaceObject dso, String type) {
try {
String resPoliciesStr = provenanceService.removedReadPolicies(context, dso, type);
String resPoliciesStr = provenanceProvider.removedReadPolicies(context, dso, type);
if (Objects.isNull(resPoliciesStr)) {
return;
}
Expand Down Expand Up @@ -591,7 +589,7 @@ private void setBitstreamPolicies(Bitstream bitstream, Item item, BulkAccessCont

itemService.adjustBitstreamPolicies(context, item, item.getOwningCollection(), bitstream);
mediaFilterService.updatePoliciesOfDerivativeBitstreams(context, item, bitstream);
provenanceService.setBitstreamPolicies(context, bitstream, item, accessControl);
provenanceProvider.setBitstreamPolicies(context, bitstream, item, accessControl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.dspace.app.bulkaccesscontrol.model.BulkAccessControlInput;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.ResourcePolicyService;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
Expand All @@ -30,31 +31,27 @@
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.MetadataValue;
import org.dspace.content.clarin.ClarinLicenseResourceMapping;
import org.dspace.content.factory.ClarinServiceFactory;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.clarin.ClarinItemService;
import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService;
import org.springframework.beans.factory.annotation.Autowired;

/**
* ProvenanceServiceImpl is responsible for creating provenance metadata for items based on the actions performed.
* It implements the ProvenanceService interface.
* Provenance is responsible for creating provenance metadata for items based on the actions performed.
*
* @author Michaela Paurikova (dspace at dataquest.sk)
*/
public class ProvenanceServiceImpl implements ProvenanceService {
private static final Logger log = LogManager.getLogger(ProvenanceServiceImpl.class);
public class ProvenanceProvider {
private static final Logger log = LogManager.getLogger(ProvenanceProvider.class);

@Autowired
private ItemService itemService;
@Autowired
private ResourcePolicyService resourcePolicyService;
@Autowired
private ClarinItemService clarinItemService;
@Autowired
private ClarinLicenseResourceMappingService clarinResourceMappingService;
@Autowired
private BitstreamService bitstreamService;
private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
private ResourcePolicyService resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService();
private ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService();
private ClarinLicenseResourceMappingService clarinResourceMappingService = ClarinServiceFactory.getInstance().getClarinLicenseResourceMappingService();
private BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();

private final ProvenanceMessageProvider messageProvider = new ProvenanceMessageProviderImpl();

Expand Down Expand Up @@ -98,7 +95,6 @@ private String findLicenseInBundles(Item item, String bundleName, String current
return currentLicense;
}

@Override
public void setItemPolicies(Context context, Item item, BulkAccessControlInput accessControl)
throws SQLException, AuthorizeException {
String resPoliciesStr = extractAccessConditions(accessControl.getItem().getAccessConditions());
Expand All @@ -109,7 +105,6 @@ public void setItemPolicies(Context context, Item item, BulkAccessControlInput a
}
}

@Override
public String removedReadPolicies(Context context, DSpaceObject dso, String type)
throws SQLException, AuthorizeException {
List<ResourcePolicy> resPolicies = resourcePolicyService.find(context, dso, type);
Expand All @@ -134,7 +129,6 @@ public String removedReadPolicies(Context context, DSpaceObject dso, String type
return resPoliciesStr;
}

@Override
public void setBitstreamPolicies(Context context, Bitstream bitstream, Item item,
BulkAccessControlInput accessControl) throws SQLException, AuthorizeException {
String accConditionsStr = extractAccessConditions(accessControl.getBitstream().getAccessConditions());
Expand All @@ -145,7 +139,6 @@ public void setBitstreamPolicies(Context context, Bitstream bitstream, Item item
}
}

@Override
public void editLicense(Context context, Item item, boolean newLicense) throws SQLException, AuthorizeException {
String oldLicense = null;
oldLicense = findLicenseInBundles(item, Constants.LICENSE_BUNDLE_NAME, oldLicense, context);
Expand All @@ -159,8 +152,6 @@ public void editLicense(Context context, Item item, boolean newLicense) throws S
addProvenanceMetadata(context, item, msg);
}


@Override
public void moveItem(Context context, Item item, Collection collection) throws SQLException, AuthorizeException {
String msg = messageProvider.getMessage(context, "moveItem", item, collection.getID());
// Update item in DB
Expand All @@ -170,20 +161,17 @@ public void moveItem(Context context, Item item, Collection collection) throws S
context.restoreAuthSystemState();
}

@Override
public void mappedItem(Context context, Item item, Collection collection) throws SQLException, AuthorizeException {
String msg = messageProvider.getMessage(context, "mappedItem", collection.getID());
addProvenanceMetadata(context, item, msg);
}

@Override
public void deletedItemFromMapped(Context context, Item item, Collection collection)
throws SQLException, AuthorizeException {
String msg = messageProvider.getMessage(context, "deletedItemFromMapped", collection.getID());
addProvenanceMetadata(context, item, msg);
}

@Override
public void deleteBitstream(Context context,Bitstream bitstream) throws SQLException, AuthorizeException {
Item item = getItem(context, bitstream);
if (Objects.nonNull(item)) {
Expand All @@ -193,7 +181,6 @@ public void deleteBitstream(Context context,Bitstream bitstream) throws SQLExcep
}
}

@Override
public void addMetadata(Context context, DSpaceObject dso, MetadataField metadataField)
throws SQLException, AuthorizeException {
if (Constants.ITEM == dso.getType()) {
Expand All @@ -214,7 +201,6 @@ public void addMetadata(Context context, DSpaceObject dso, MetadataField metadat
}
}

@Override
public void removeMetadata(Context context, DSpaceObject dso, MetadataField metadataField)
throws SQLException, AuthorizeException {
if (dso.getType() != Constants.BITSTREAM) {
Expand All @@ -239,7 +225,6 @@ public void removeMetadata(Context context, DSpaceObject dso, MetadataField meta
}
}

@Override
public void removeMetadataAtIndex(Context context, DSpaceObject dso, List<MetadataValue> metadataValues,
int indexInt) throws SQLException, AuthorizeException {
if (dso.getType() != Constants.ITEM) {
Expand All @@ -253,7 +238,6 @@ public void removeMetadataAtIndex(Context context, DSpaceObject dso, List<Metada
addProvenanceMetadata(context, (Item) dso, msg);
}

@Override
public void replaceMetadata(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal)
throws SQLException, AuthorizeException {
if (dso.getType() != Constants.ITEM) {
Expand All @@ -265,7 +249,6 @@ public void replaceMetadata(Context context, DSpaceObject dso, MetadataField met
addProvenanceMetadata(context, (Item) dso, msg);
}

@Override
public void replaceMetadataSingle(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal)
throws SQLException, AuthorizeException {
if (dso.getType() != Constants.BITSTREAM) {
Expand All @@ -282,15 +265,13 @@ public void replaceMetadataSingle(Context context, DSpaceObject dso, MetadataFie
}
}

@Override
public void makeDiscoverable(Context context, Item item, boolean discoverable)
throws SQLException, AuthorizeException {
String msg = messageProvider.getMessage(context, "discoverable",
item, discoverable ? "" : "non-") + messageProvider.addCollectionsToMessage(item);
addProvenanceMetadata(context, item, msg);
}

@Override
public void uploadBitstream(Context context, Bundle bundle) throws SQLException, AuthorizeException {
Item item = bundle.getItems().get(0);
String msg = messageProvider.getMessage(context, "bundleAdded", item, bundle.getID());
Expand Down
58 changes: 0 additions & 58 deletions dspace-api/src/main/java/org/dspace/core/ProvenanceService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.dspace.core.factory;

import org.dspace.core.ProvenanceService;
import org.dspace.core.service.LicenseService;
import org.dspace.core.service.NewsService;
import org.dspace.core.service.PluginService;
Expand All @@ -30,8 +29,6 @@ public abstract class CoreServiceFactory {

public abstract ClientInfoService getClientInfoService();

public abstract ProvenanceService getProvenanceService();

public static CoreServiceFactory getInstance() {
return DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName("coreServiceFactory", CoreServiceFactory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.dspace.core.factory;

import org.dspace.core.ProvenanceService;
import org.dspace.core.service.LicenseService;
import org.dspace.core.service.NewsService;
import org.dspace.core.service.PluginService;
Expand All @@ -34,9 +33,6 @@ public class CoreServiceFactoryImpl extends CoreServiceFactory {
@Autowired(required = true)
private ClientInfoService clientInfoService;

@Autowired(required = true)
private ProvenanceService provenanceService;

@Override
public LicenseService getLicenseService() {
return licenseService;
Expand All @@ -55,9 +51,4 @@ public PluginService getPluginService() {
public ClientInfoService getClientInfoService() {
return clientInfoService;
}

@Override
public ProvenanceService getProvenanceService() {
return provenanceService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.dspace.content.Bundle;
import org.dspace.content.service.BundleService;
import org.dspace.core.Context;
import org.dspace.core.ProvenanceService;
import org.dspace.core.ProvenanceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.ControllerUtils;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
Expand Down Expand Up @@ -79,8 +79,7 @@ public class BundleUploadBitstreamController {
@Autowired
private ConverterService converter;

@Autowired
private ProvenanceService provenanceService;
private ProvenanceProvider provenanceProvider = new ProvenanceProvider();

/**
* Method to upload a Bitstream to a Bundle with the given UUID in the URL. This will create a Bitstream with the
Expand Down Expand Up @@ -117,7 +116,7 @@ public ResponseEntity<RepresentationModel<?>> uploadBitstream(
throw new UnprocessableEntityException("The InputStream from the file couldn't be read", e);
}
try {
provenanceService.uploadBitstream(context, bundle);
provenanceProvider.uploadBitstream(context, bundle);
} catch (SQLException ex) {
msg = "SQLException in BundleUploadBitstreamConverter.uploadBitstream when " +
"adding new provenance metadata.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.dspace.content.service.clarin.ClarinLicenseService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.ProvenanceService;
import org.dspace.core.ProvenanceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -99,8 +99,7 @@ public class ItemAddBundleController {
@Autowired
ClarinLicenseResourceMappingService clarinLicenseResourceMappingService;

@Autowired
ProvenanceService provenanceService;
ProvenanceProvider provenanceProvider = new ProvenanceProvider();

/**
* Method to add a Bundle to an Item with the given UUID in the URL. This will create a Bundle with the
Expand Down Expand Up @@ -169,7 +168,7 @@ public ItemRest updateLicenseForBundle(@PathVariable UUID uuid,
log.warn("Cannot find clarin license with id: " + licenseId + ". The old license will be detached, " +
"but the new one will not be attached.");
}
provenanceService.editLicense(context, item, !Objects.isNull(clarinLicense));
provenanceProvider.editLicense(context, item, !Objects.isNull(clarinLicense));
List<Bundle> bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME);
for (Bundle clarinBundle : bundles) {
List<Bitstream> bitstreamList = clarinBundle.getBitstreams();
Expand Down
Loading

0 comments on commit 49cae22

Please sign in to comment.