Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions dspace-oai/src/main/java/org/dspace/xoai/app/XOAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ private SolrInputDocument index(Item item)
if (!discoverable && item.isHidden()) {
discoverable = true;
}
doc.addField("item.deleted",
(item.isWithdrawn() || (!discoverable) || (isEmbargoed ? isPublic : false)));
boolean isDeleted = item.isWithdrawn() || (!discoverable) || (isEmbargoed && isPublic);
doc.addField("item.deleted", isDeleted);

/*
* An item that is embargoed will potentially not be harvested by incremental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;

Expand All @@ -26,11 +27,13 @@
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.repository.patch.ResourcePatch;
import org.dspace.app.rest.utils.DSpaceObjectUtils;
import org.dspace.app.rest.utils.SolrOAIReindexer;
import org.dspace.app.rest.utils.Utils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.authorize.service.ResourcePolicyService;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
Expand Down Expand Up @@ -76,6 +79,9 @@ public class ResourcePolicyRestRepository extends DSpaceRestRepository<ResourceP
@Autowired
DiscoverableEndpointsService discoverableEndpointsService;

@Autowired
private SolrOAIReindexer solrOAIReindexer;

@Override
@PreAuthorize("hasPermission(#id, 'resourcepolicy', 'READ')")
public ResourcePolicyRest findOne(Context context, Integer id) {
Expand Down Expand Up @@ -275,6 +281,7 @@ protected ResourcePolicyRest createAndReturn(Context context) throws AuthorizeEx
} catch (SQLException excSQL) {
throw new RuntimeException(excSQL.getMessage(), excSQL);
}
reindexSolrOAI(resourcePolicy.getdSpaceObject());
return converter.toRest(resourcePolicy, utils.obtainProjection());
} else {
try {
Expand All @@ -288,6 +295,7 @@ protected ResourcePolicyRest createAndReturn(Context context) throws AuthorizeEx
} catch (SQLException excSQL) {
throw new RuntimeException(excSQL.getMessage(), excSQL);
}
reindexSolrOAI(resourcePolicy.getdSpaceObject());
return converter.toRest(resourcePolicy, utils.obtainProjection());
}
}
Expand All @@ -296,16 +304,21 @@ protected ResourcePolicyRest createAndReturn(Context context) throws AuthorizeEx
@PreAuthorize("hasAuthority('ADMIN')")
protected void delete(Context context, Integer id) throws AuthorizeException {
ResourcePolicy resourcePolicy = null;
DSpaceObject dso = null;
try {
resourcePolicy = resourcePolicyService.find(context, id);
if (resourcePolicy == null) {
throw new ResourceNotFoundException(
ResourcePolicyRest.CATEGORY + "." + ResourcePolicyRest.NAME + " with id: " + id + " not found");
}
dso = resourcePolicy.getdSpaceObject();
resourcePolicyService.delete(context, resourcePolicy);
} catch (SQLException e) {
throw new RuntimeException("Unable to delete ResourcePolicy with id = " + id, e);
}
if (Objects.nonNull(dso) && dso instanceof Item) {
solrOAIReindexer.deleteItem((Item) dso);
}
}

@Override
Expand All @@ -319,6 +332,7 @@ protected void patch(Context context, HttpServletRequest request, String apiCate
}
resourcePatch.patch(obtainContext(), resourcePolicy, patch.getOperations());
resourcePolicyService.update(context, resourcePolicy);
reindexSolrOAI(resourcePolicy.getdSpaceObject());
}

@Override
Expand All @@ -327,4 +341,11 @@ public void afterPropertiesSet() throws Exception {
Link.of("/api/" + ResourcePolicyRest.CATEGORY + "/" + ResourcePolicyRest.PLURAL_NAME + "/search",
ResourcePolicyRest.PLURAL_NAME + "-search")));
}

private void reindexSolrOAI(DSpaceObject dso) {
// reindex solr only if dso is item
if (Objects.nonNull(dso) && dso instanceof Item) {
solrOAIReindexer.reindexItem((Item) dso);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrDocumentList;
Expand Down Expand Up @@ -188,12 +189,14 @@ private SolrInputDocument index(Item item) throws SQLException, IOException, XML
* invisible embargoed items, because this will override the item.public
* flag.
*/
boolean deleted = false;
if (!item.isHidden()) {
deleted = (item.isWithdrawn() || !item.isDiscoverable() || (isEmbargoed && isPublic));
boolean discoverable = item.isDiscoverable();
// The Item is not deleted when it has local metadata `local.hidden = hidden`.
// Without this, the item is not discoverable and harvestable; however, it should be harvestable via OAI-PMH.
if (!discoverable && item.isHidden()) {
discoverable = true;
}
doc.addField("item.deleted", deleted);

boolean isDeleted = item.isWithdrawn() || (!discoverable) || (isEmbargoed && isPublic);
doc.addField("item.deleted", isDeleted);

/*
* An item that is embargoed will potentially not be harvested by
Expand Down Expand Up @@ -307,9 +310,12 @@ public void reindexItem(Item item) {
return;
}
try {
// Before reindexing delete item
deleteItemByQuery(item);
SolrClient server = solrServerResolver.getServer();
SolrInputDocument solrInput = index(item);
solrServerResolver.getServer().add(solrInput);
solrServerResolver.getServer().commit();
server.add(solrInput);
server.commit();
cacheService.deleteAll();
itemCacheService.deleteAll();
} catch (IOException | XMLStreamException | SQLException | WritingXmlException | SolrServerException e) {
Expand All @@ -326,8 +332,7 @@ public void reindexItem(Item item) {

public void deleteItem(Item item) {
try {
solrServerResolver.getServer().deleteByQuery("item.id:" + item.getID().toString());
solrServerResolver.getServer().commit();
deleteItemByQuery(item);
cacheService.deleteAll();
itemCacheService.deleteAll();
} catch (SolrServerException | IOException e) {
Expand Down Expand Up @@ -356,4 +361,13 @@ private boolean isTest() {

return false;
}

/**
* Delete the item from Solr by the ID of the item
*/
private void deleteItemByQuery(Item item) throws SolrServerException, IOException {
SolrClient solrClient = solrServerResolver.getServer();
solrClient.deleteByQuery("item.id:" + item.getID().toString());
solrClient.commit();
}
}