Skip to content

Commit

Permalink
Improve error reporting and state
Browse files Browse the repository at this point in the history
Affects: #72
Affects: #71
  • Loading branch information
io7m committed Sep 29, 2024
1 parent d9a319b commit 6f86484
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.laurel.filemodel;

/**
* The file model encountered an error.
*
* @param error The error
*/

public record LFileModelStatusError(
LFileModelEventError error)
implements LFileModelStatusType
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.laurel.filemodel;

/**
* The file model is idle.
*/

public record LFileModelStatusIdle()
implements LFileModelStatusType
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.laurel.filemodel;

/**
* The file model is loading.
*/

public record LFileModelStatusLoading()
implements LFileModelStatusType
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.laurel.filemodel;

/**
* The file model is running a command.
*/

public record LFileModelStatusRunningCommand()
implements LFileModelStatusType
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.laurel.filemodel;

/**
* The status of a file model.
*/

public sealed interface LFileModelStatusType
permits LFileModelStatusError,
LFileModelStatusIdle,
LFileModelStatusLoading,
LFileModelStatusRunningCommand
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public interface LFileModelType

Flow.Publisher<LFileModelEventType> events();

/**
* @return An observable status value for the file model
*/

AttributeReadableType<LFileModelStatusType> status();

/**
* Add a global caption.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.io7m.laurel.filemodel.internal;

import com.io7m.darco.api.DDatabaseUnit;
import com.io7m.laurel.filemodel.LFileModelStatusLoading;
import org.jooq.DSLContext;

import java.util.Properties;
Expand Down Expand Up @@ -64,6 +65,8 @@ protected LCommandUndoable onExecute(
final LDatabaseTransactionType transaction,
final DDatabaseUnit request)
{
model.setStatus(new LFileModelStatusLoading());

final var context = transaction.get(DSLContext.class);

model.eventWithProgress(0.0, "Loading images…");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@

public interface LCommandType<P>
{
/**
* @return {@code true} if this command indicates the file model is loading
*/

default boolean loading()
{
return false;
}

/**
* @return {@code true} if the database should be compacted after this command
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import com.io7m.laurel.filemodel.LExportRequest;
import com.io7m.laurel.filemodel.LFileModelEvent;
import com.io7m.laurel.filemodel.LFileModelEventType;
import com.io7m.laurel.filemodel.LFileModelStatusIdle;
import com.io7m.laurel.filemodel.LFileModelStatusLoading;
import com.io7m.laurel.filemodel.LFileModelStatusRunningCommand;
import com.io7m.laurel.filemodel.LFileModelStatusType;
import com.io7m.laurel.filemodel.LFileModelType;
import com.io7m.laurel.filemodel.LImageCaptionsAssignment;
import com.io7m.laurel.filemodel.LImageComparison;
Expand Down Expand Up @@ -131,6 +135,7 @@ public final class LFileModel implements LFileModelType
private final SubmissionPublisher<LFileModelEventType> events;
private final AttributeType<List<LValidationProblemType>> validationProblems;
private final AttributeType<List<LFileModelEventType>> exportEvents;
private final AttributeType<LFileModelStatusType> status;

private LFileModel(
final LDatabaseType inDatabase)
Expand Down Expand Up @@ -189,6 +194,8 @@ private LFileModel(
ATTRIBUTES.withValue(List.of());
this.validationProblems =
ATTRIBUTES.withValue(List.of());
this.status =
ATTRIBUTES.withValue(new LFileModelStatusLoading());
this.commandLock =
new ReentrantLock();
this.attributes =
Expand Down Expand Up @@ -523,6 +530,12 @@ public SubmissionPublisher<LFileModelEventType> events()
return this.events;
}

@Override
public AttributeReadableType<LFileModelStatusType> status()
{
return this.status;
}

@Override
public CompletableFuture<?> globalCaptionAdd(
final LCaptionName text)
Expand Down Expand Up @@ -799,7 +812,14 @@ public CompletableFuture<?> metadataRemove(
Thread.ofVirtual()
.start(() -> {
try {
if (command.loading()) {
this.status.set(new LFileModelStatusLoading());
} else {
this.status.set(new LFileModelStatusRunningCommand());
}

this.executeCommandLocked(command, parameters);
this.status.set(new LFileModelStatusIdle());
future.complete(null);
} catch (final Throwable e) {
future.completeExceptionally(e);
Expand Down Expand Up @@ -1507,4 +1527,10 @@ void setExportEvents(
{
this.exportEvents.set(newEvents);
}

void setStatus(
final LFileModelStatusType newStatus)
{
this.status.set(newStatus);
}
}
8 changes: 8 additions & 0 deletions com.io7m.laurel.gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
<groupId>com.io7m.jwheatsheaf</groupId>
<artifactId>com.io7m.jwheatsheaf.ui</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.miscue</groupId>
<artifactId>com.io7m.miscue.fx.seltzer</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.seltzer</groupId>
<artifactId>com.io7m.seltzer.api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Loading

0 comments on commit 6f86484

Please sign in to comment.