mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[CST-5269] refactored sherpaPolicy step
This commit is contained in:
@@ -8,7 +8,11 @@
|
||||
package org.dspace.app.sherpa.cache;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.dspace.app.sherpa.submit.SHERPASubmitService;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -26,9 +30,14 @@ public class SherpaCacheEvictService {
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
@Autowired
|
||||
private SHERPASubmitService sherpaSubmitService;
|
||||
|
||||
public void evictSingleCacheValue(String cacheKey) {
|
||||
Objects.requireNonNull(cacheManager.getCache(CACHE_NAME)).evict(cacheKey);
|
||||
public void evictCacheValues(Context context, Item item) {
|
||||
Set<String> ISSNs = sherpaSubmitService.getISSNs(context, item);
|
||||
for (String issn : ISSNs) {
|
||||
Objects.requireNonNull(cacheManager.getCache(CACHE_NAME)).evict(issn);
|
||||
}
|
||||
}
|
||||
|
||||
public void evictAllCacheValues() {
|
||||
|
@@ -82,12 +82,13 @@ public class SHERPASubmitService {
|
||||
// Continue with loop
|
||||
log.warn("Failed to look up SHERPA ROMeO result for ISSN: " + issn
|
||||
+ ": " + response.getMessage());
|
||||
return new SHERPAResponse("SHERPA ROMeO lookup failed");
|
||||
} else if (!response.getJournals().isEmpty()) {
|
||||
// return this response, if it is not empty
|
||||
return response;
|
||||
}
|
||||
}
|
||||
return new SHERPAResponse("SHERPA ROMeO lookup failed");
|
||||
return new SHERPAResponse();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -76,6 +76,11 @@ public class SHERPAResponse {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty SHERPAResponse rappresentation
|
||||
*/
|
||||
public SHERPAResponse() {}
|
||||
|
||||
/**
|
||||
* Parse the SHERPA v2 API JSON and construct Romeo policy data for display
|
||||
* This method does not return a value, but rather populates the metadata and journals objects
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.rest.submit.step;
|
||||
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
@@ -30,11 +31,14 @@ public class SherpaPolicyStep extends AbstractProcessingStep {
|
||||
@SuppressWarnings("unchecked")
|
||||
public SherpaPolicy getData(SubmissionService submissionService, InProgressSubmission obj,
|
||||
SubmissionStepConfig config) throws Exception {
|
||||
SherpaPolicy result = new SherpaPolicy();
|
||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||
SHERPAResponse response = sherpaSubmitService.searchRelatedJournals(context, obj.getItem());
|
||||
result.setSherpaResponse(response);
|
||||
return result;
|
||||
if (Objects.nonNull(response)) {
|
||||
SherpaPolicy result = new SherpaPolicy();
|
||||
result.setSherpaResponse(response);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,8 +47,7 @@ public class SherpaPolicyStep extends AbstractProcessingStep {
|
||||
String path = op.getPath();
|
||||
SherpaCacheEvictService sherpaCacheEvictService = SherpaCacheEvictBeanLocator.getSherpaCacheEvictService();
|
||||
if (path.contains(SHERPA_RETRIEVAL_TIME)) {
|
||||
// uuid or issn?
|
||||
sherpaCacheEvictService.evictSingleCacheValue(source.getItem().getID().toString());
|
||||
sherpaCacheEvictService.evictCacheValues(context, source.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user