Skip to content

Commit

Permalink
Fix #8714 and #8715
Browse files Browse the repository at this point in the history
  • Loading branch information
amgciadev committed Mar 11, 2023
1 parent b956bcd commit 4748163
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
62 changes: 34 additions & 28 deletions dspace-api/src/main/java/org/dspace/discovery/IndexClient.java
Expand Up @@ -56,37 +56,18 @@ public void internalRun() throws Exception {
* new DSpace.getServiceManager().getServiceByName("org.dspace.discovery.SolrIndexer");
*/

if (indexClientOptions == IndexClientOptions.REMOVE) {
handler.logInfo("Removing " + commandLine.getOptionValue("r") + " from Index");
indexer.unIndexContent(context, commandLine.getOptionValue("r"));
} else if (indexClientOptions == IndexClientOptions.CLEAN) {
handler.logInfo("Cleaning Index");
indexer.cleanIndex();
} else if (indexClientOptions == IndexClientOptions.DELETE) {
handler.logInfo("Deleting Index");
indexer.deleteIndex();
} else if (indexClientOptions == IndexClientOptions.BUILD ||
indexClientOptions == IndexClientOptions.BUILDANDSPELLCHECK) {
handler.logInfo("(Re)building index from scratch.");
indexer.deleteIndex();
indexer.createIndex(context);
if (indexClientOptions == IndexClientOptions.BUILDANDSPELLCHECK) {
checkRebuildSpellCheck(commandLine, indexer);
}
} else if (indexClientOptions == IndexClientOptions.OPTIMIZE) {
handler.logInfo("Optimizing search core.");
indexer.optimize();
} else if (indexClientOptions == IndexClientOptions.SPELLCHECK) {
checkRebuildSpellCheck(commandLine, indexer);
} else if (indexClientOptions == IndexClientOptions.INDEX) {
final String param = commandLine.getOptionValue('i');
Optional<IndexableObject> indexableObject = Optional.empty();

Check warning on line 59 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L59

Added line #L59 was not covered by tests

if (indexClientOptions == IndexClientOptions.REMOVE || indexClientOptions == IndexClientOptions.INDEX) {
final String param = indexClientOptions == IndexClientOptions.REMOVE ? commandLine.getOptionValue('r') :
commandLine.getOptionValue('i');

Check warning on line 63 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L63

Added line #L63 was not covered by tests
UUID uuid = null;
try {
uuid = UUID.fromString(param);
} catch (Exception e) {
// nothing to do, it should be an handle
// nothing to do, it should be a handle
}
Optional<IndexableObject> indexableObject = Optional.empty();

if (uuid != null) {
final Item item = ContentServiceFactory.getInstance().getItemService().find(context, uuid);
if (item != null) {
Expand Down Expand Up @@ -118,7 +99,32 @@ public void internalRun() throws Exception {
if (!indexableObject.isPresent()) {
throw new IllegalArgumentException("Cannot resolve " + param + " to a DSpace object");
}
handler.logInfo("Indexing " + param + " force " + commandLine.hasOption("f"));
}

if (indexClientOptions == IndexClientOptions.REMOVE) {
handler.logInfo("Removing " + commandLine.getOptionValue("r") + " from Index");
indexer.unIndexContent(context, indexableObject.get().getUniqueIndexID());

Check warning on line 106 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L105-L106

Added lines #L105 - L106 were not covered by tests
} else if (indexClientOptions == IndexClientOptions.CLEAN) {
handler.logInfo("Cleaning Index");
indexer.cleanIndex();

Check warning on line 109 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L108-L109

Added lines #L108 - L109 were not covered by tests
} else if (indexClientOptions == IndexClientOptions.DELETE) {
handler.logInfo("Deleting Index");
indexer.deleteIndex();

Check warning on line 112 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L111-L112

Added lines #L111 - L112 were not covered by tests
} else if (indexClientOptions == IndexClientOptions.BUILD ||
indexClientOptions == IndexClientOptions.BUILDANDSPELLCHECK) {
handler.logInfo("(Re)building index from scratch.");
indexer.deleteIndex();
indexer.createIndex(context);

Check warning on line 117 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L115-L117

Added lines #L115 - L117 were not covered by tests
if (indexClientOptions == IndexClientOptions.BUILDANDSPELLCHECK) {
checkRebuildSpellCheck(commandLine, indexer);

Check warning on line 119 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L119

Added line #L119 was not covered by tests
}
} else if (indexClientOptions == IndexClientOptions.OPTIMIZE) {
handler.logInfo("Optimizing search core.");
indexer.optimize();

Check warning on line 123 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L122-L123

Added lines #L122 - L123 were not covered by tests
} else if (indexClientOptions == IndexClientOptions.SPELLCHECK) {
checkRebuildSpellCheck(commandLine, indexer);

Check warning on line 125 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L125

Added line #L125 was not covered by tests
} else if (indexClientOptions == IndexClientOptions.INDEX) {
handler.logInfo("Indexing " + commandLine.getOptionValue('i') + " force " + commandLine.hasOption("f"));

Check warning on line 127 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L127

Added line #L127 was not covered by tests
final long startTimeMillis = System.currentTimeMillis();
final long count = indexAll(indexer, ContentServiceFactory.getInstance().
getItemService(), context, indexableObject.get());
Expand Down Expand Up @@ -179,7 +185,7 @@ private static long indexAll(final IndexingService indexingService,
indexingService.indexContent(context, dso, true, true);
count++;
if (dso.getIndexedObject() instanceof Community) {
final Community community = (Community) dso;
final Community community = (Community) dso.getIndexedObject();

Check warning on line 188 in dspace-api/src/main/java/org/dspace/discovery/IndexClient.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/IndexClient.java#L188

Added line #L188 was not covered by tests
final String communityHandle = community.getHandle();
for (final Community subcommunity : community.getSubcommunities()) {
count += indexAll(indexingService, itemService, context, new IndexableCommunity(subcommunity));
Expand Down
Expand Up @@ -107,6 +107,10 @@ static List<String> findDirectlyAuthorizedGroupAndEPersonPrefixedIds(
ArrayList<String> prefixedIds = new ArrayList<>();
for (int auth : authorizations) {
for (ResourcePolicy policy : authService.getPoliciesActionFilter(context, obj, auth)) {
// Avoid NPE in cases where the policy does not have group or eperson
if (policy.getGroup() == null && policy.getEPerson() == null) {
continue;
}
String prefixedId = policy.getGroup() == null
? "e" + policy.getEPerson().getID()
: "g" + policy.getGroup().getID();
Expand Down
Expand Up @@ -256,7 +256,12 @@ public void unIndexContent(Context context, String searchUniqueID, boolean commi

try {
if (solrSearchCore.getSolr() != null) {
indexObjectServiceFactory.getIndexableObjectFactory(searchUniqueID).delete(searchUniqueID);
IndexFactory index = indexObjectServiceFactory.getIndexableObjectFactory(searchUniqueID);
if (index != null) {
index.delete(searchUniqueID);
} else {
log.warn("Object not found in Solr index: " + searchUniqueID);

Check warning on line 263 in dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java#L263

Added line #L263 was not covered by tests
}
if (commit) {
solrSearchCore.getSolr().commit();
}
Expand Down

0 comments on commit 4748163

Please sign in to comment.