Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk unindexing for IndexerInterface #598

Merged
merged 13 commits into from
Aug 27, 2024
Prev Previous commit
Next Next commit
[sdk] Reiterate on the UnindexReport API
- record a collection of URIs in each unindex failure
  • Loading branch information
Enet4 committed Apr 17, 2024
commit 216b11fb603680f6674e70fc633abd0ba69e6876
4 changes: 2 additions & 2 deletions sdk/src/main/java/pt/ua/dicoogle/sdk/IndexerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public default Task<UnindexReport> unindex(Collection<URI> uris, Consumer<Collec
}
} else {
// failed to unindex, reason unknown
failures.add(new FailedUnindex(uri, null));
failures.add(new FailedUnindex(Collections.singleton(uri), null));
}
} catch (Exception ex) {
failures.add(new FailedUnindex(uri, ex));
failures.add(new FailedUnindex(Collections.singleton(uri), ex));
}
}
return UnindexReport.withFailures(failures);
tiberio-baptista marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
39 changes: 23 additions & 16 deletions sdk/src/main/java/pt/ua/dicoogle/sdk/datastructs/UnindexReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
*/
public final class UnindexReport implements Serializable {

/** The description of a file which
* could not be unindexed due to an error.
*
* When an error of this kind occurs,
* it is not specified whether the file remains indexed or not.
/** The description of an indexing error.
*
* Whether the file remains indexed or not
* when an error of this kind occurs
* is not specified.
*/
public static final class FailedUnindex implements Serializable {
/** The URI to the item which failed to unindex. */
public final URI uri;
/** The URIs to the items which failed to unindex. */
public final Collection<URI> urisAffected;

/** The exception describing the error which led to the failure.
* This field can be <code>null</code>
Expand All @@ -50,11 +50,16 @@ public static final class FailedUnindex implements Serializable {
* @param uri the URI of the file which could not be unindexed
* @param cause the underlying exception, if any
*/
public FailedUnindex(URI uri, Exception cause) {
Objects.requireNonNull(uri);
this.uri = uri;
public FailedUnindex(Collection<URI> urisAffected, Exception cause) {
Objects.requireNonNull(urisAffected);
this.urisAffected = urisAffected;
this.cause = cause;
}

@Override
public String toString() {
return "FailedUnindex{urisAffected=" + urisAffected + ", cause=" + cause + "}";
}
}

/** URIs of files which were not found. */
Expand All @@ -64,6 +69,8 @@ public FailedUnindex(URI uri, Exception cause) {
/** Creates a full report for a bulk unindexing operation.
* All parameters are nullable,
* in which case is equivalent to passing an empty collection.
* Once created, the report is final and immutable.
*
* @param notFound the URIs of files which were not found
* @param failures the error reports of files which could not be unindexed
*/
Expand All @@ -78,13 +85,13 @@ public UnindexReport(Collection<URI> notFound, Collection<FailedUnindex> failure
this.failures = failures;
}

/** Creates a report that all files were successfully unindexed. */
/** Creates a report with no unindexing failures.
*/
public static UnindexReport ok() {
return new UnindexReport(null, null);
}

/** Creates a report with the files which failed to unindex
* due to some error.
/** Creates a report with the given failures.
*/
public static UnindexReport withFailures(Collection<FailedUnindex> failures) {
return new UnindexReport(null, failures);
Expand All @@ -110,7 +117,7 @@ public boolean allUnindexed() {
}

/** Obtains an immutable collection to
* the files which failed to unindex due to an error.
* the file batches which failed to unindex due to errors.
*/
public Collection<FailedUnindex> getUnindexFailures() {
return Collections.unmodifiableCollection(this.failures);
Expand All @@ -123,8 +130,8 @@ public Collection<URI> getNotFound() {
return Collections.unmodifiableCollection(this.notFound);
}

/** Return the total count of files which were requested to be unindexed,
* but were either not found or failed to unindex.
/** Returns the total count of errors reported during unindexing
* due to either not having been found or other failures.
*/
public long errorCount() {
return this.failures.size() + this.notFound.size();
Expand Down
Loading