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;
|
package org.dspace.app.sherpa.cache;
|
||||||
|
|
||||||
import java.util.Objects;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -26,9 +30,14 @@ public class SherpaCacheEvictService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CacheManager cacheManager;
|
private CacheManager cacheManager;
|
||||||
|
@Autowired
|
||||||
|
private SHERPASubmitService sherpaSubmitService;
|
||||||
|
|
||||||
public void evictSingleCacheValue(String cacheKey) {
|
public void evictCacheValues(Context context, Item item) {
|
||||||
Objects.requireNonNull(cacheManager.getCache(CACHE_NAME)).evict(cacheKey);
|
Set<String> ISSNs = sherpaSubmitService.getISSNs(context, item);
|
||||||
|
for (String issn : ISSNs) {
|
||||||
|
Objects.requireNonNull(cacheManager.getCache(CACHE_NAME)).evict(issn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evictAllCacheValues() {
|
public void evictAllCacheValues() {
|
||||||
|
@@ -82,12 +82,13 @@ public class SHERPASubmitService {
|
|||||||
// Continue with loop
|
// Continue with loop
|
||||||
log.warn("Failed to look up SHERPA ROMeO result for ISSN: " + issn
|
log.warn("Failed to look up SHERPA ROMeO result for ISSN: " + issn
|
||||||
+ ": " + response.getMessage());
|
+ ": " + response.getMessage());
|
||||||
|
return new SHERPAResponse("SHERPA ROMeO lookup failed");
|
||||||
} else if (!response.getJournals().isEmpty()) {
|
} else if (!response.getJournals().isEmpty()) {
|
||||||
// return this response, if it is not empty
|
// return this response, if it is not empty
|
||||||
return response;
|
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
|
* 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
|
* 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;
|
package org.dspace.app.rest.submit.step;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.app.rest.model.patch.Operation;
|
import org.dspace.app.rest.model.patch.Operation;
|
||||||
@@ -30,11 +31,14 @@ public class SherpaPolicyStep extends AbstractProcessingStep {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SherpaPolicy getData(SubmissionService submissionService, InProgressSubmission obj,
|
public SherpaPolicy getData(SubmissionService submissionService, InProgressSubmission obj,
|
||||||
SubmissionStepConfig config) throws Exception {
|
SubmissionStepConfig config) throws Exception {
|
||||||
SherpaPolicy result = new SherpaPolicy();
|
|
||||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||||
SHERPAResponse response = sherpaSubmitService.searchRelatedJournals(context, obj.getItem());
|
SHERPAResponse response = sherpaSubmitService.searchRelatedJournals(context, obj.getItem());
|
||||||
result.setSherpaResponse(response);
|
if (Objects.nonNull(response)) {
|
||||||
return result;
|
SherpaPolicy result = new SherpaPolicy();
|
||||||
|
result.setSherpaResponse(response);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,8 +47,7 @@ public class SherpaPolicyStep extends AbstractProcessingStep {
|
|||||||
String path = op.getPath();
|
String path = op.getPath();
|
||||||
SherpaCacheEvictService sherpaCacheEvictService = SherpaCacheEvictBeanLocator.getSherpaCacheEvictService();
|
SherpaCacheEvictService sherpaCacheEvictService = SherpaCacheEvictBeanLocator.getSherpaCacheEvictService();
|
||||||
if (path.contains(SHERPA_RETRIEVAL_TIME)) {
|
if (path.contains(SHERPA_RETRIEVAL_TIME)) {
|
||||||
// uuid or issn?
|
sherpaCacheEvictService.evictCacheValues(context, source.getItem());
|
||||||
sherpaCacheEvictService.evictSingleCacheValue(source.getItem().getID().toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user