use of javax.enterprise.inject.Instance in project dwoss by gg-net.
the class DwOssApplication method start.
/**
* Starting the Deutsche Warenwirtschaft Open Source application.
* The startup happens through the following steps:
* <ol>
* <li>Parameter validation via <a href="https://jcommander.org/">JCommander</a>. The required and optional parametes are defined here
* {@link ConnectionParameter}.</li>
* <li>Setting the LAF for Swing components via {@link LafMenuManager#loadAndSetUserLaf() }</li>
* <li>Displaying a placeholder main pane and the blocking login screen.
* <ul>
* <li>The login screen has no authentification system on visibility but the user can already type in his username and password.</li>
* <li>The guardian is set later and only then an authentification will happen, even if the user has pressed return before.</li>
* <li>A red/green circle in the ui displays the status of the guardian (red meaning not yet set).</li>
* </ul>
* </li>
* <li>Initialize the client backend, remote connections, saft core, and preparing the main view by wrapping the javafx pane in a swing frame.
* <ul>
* <li>{@link #initSeContainer() }</li>
* <li>{@link #initGlobalExceptionHandling() }</li>
* <li>{@link #initRemoteConnection(eu.ggnet.dwoss.assembly.client.support.ConnectionParameter) }</li>
* <li>{@link #initMainPane() }</li>
* <li>{@link #startSaftInitMainFrameAndWrapMainPane(javax.swing.JFrame, javafx.scene.layout.Pane, eu.ggnet.dwoss.assembly.client.support.ConnectionParameter)
* }</li>
* </ul>
* </li>
* <li>Activating the authentification in the login screen by calling {@link LoginScreenController#setAndActivateGuardian(eu.ggnet.saft.experimental.auth.Guardian)
* with the remote guardian</li>
* <li>Start the polling of server progress {@link MonitorManager#startPolling() }</li>
* <li>Initialize the session timeout and global keys for manual logout and relocation of windows. Ctrl+Shift+L for manual logout and Ctrl+Shift+R for
* relocation of all windows</li>
* </ol>
*
* @param primaryStage primaryStage of application.
* @throws Exception all possible exeptions.
*/
@Override
public void start(Stage primaryStage) throws Exception {
try {
// Parameter discovery is done here, cause a error will be shown via Ui.
ConnectionParameter cp = new ConnectionParameter();
JCommander.newBuilder().addObject(cp).programName(DwOssMain.class.getName()).build().parse(getParameters().getRaw().toArray(new String[] {}));
L.debug("start() parameters discovered: {}", cp);
LafMenuManager.loadAndSetUserLaf();
createAndShowMainPane(primaryStage);
// Creating the Swing MainFrame as long as we are in the Swing mode.
JFrame mainFrame = new JFrame();
LoginScreenController firstLoginScreen = createAndShowFirstLoginScreen(primaryStage, mainFrame);
CompletableFuture.runAsync(() -> {
container = initSeContainer();
instance = container.getBeanManager().createInstance();
saft = instance.select(Saft.class).get();
UiCore.initGlobal(saft);
}).thenRun(() -> initGlobalExceptionHandling()).thenRun(() -> initRemoteConnection(cp)).thenApply(v -> initMainPane()).thenAcceptAsync(mainView -> startSaftInitMainFrameAndWrapMainPane(mainFrame, mainView, cp), java.awt.EventQueue::invokeLater).thenRunAsync(() -> firstLoginScreen.setAndActivateGuardian(Dl.local().lookup(Guardian.class))).thenRun(() -> initOnceViews()).thenRun(() -> instance.select(MonitorManager.class).get().startPolling()).thenRun(() -> initSessionTimeoutAndManualLogoutKeys()).thenRun(() -> initRelocationKeys()).handle((v, ex) -> {
new DwFinalExceptionConsumer(null).accept(Optional.empty(), ex);
return null;
});
} catch (ParameterException e) {
// Sout is here correct.
System.out.println(e.getMessage());
System.out.println();
e.getJCommander().usage();
Alert a = new Alert(javafx.scene.control.Alert.AlertType.ERROR);
a.setTitle("Fehler beim Start");
a.setHeaderText("Fehler bei Start.");
a.setContentText("Es ist ein Fehler beim Start aufgetreten. Bitte Console und/oder Logs prüfen.");
a.show();
}
}
use of javax.enterprise.inject.Instance in project dwoss by gg-net.
the class DwOssApplication method createAndShowFirstLoginScreen.
/**
* Creates and shows the LoginScreen in a very special first mode.
* In this phase, no cdi or saft is available. So the login screen is
* created with native fx calls. It is application modal, blocking the supplied
* owner.
* <ul>
* <li>On a successful authentication, it will close the itself and the owner stage and show the supplied mainFrame.</li>
* <li>On a cancel close, the hole application will be shutdown.</li>
* </ul>
* After the creation of the controller, no connection to any authentication system has happend.
* A call to {@link LoginScreenController#setAndActivateGuardian(eu.ggnet.saft.experimental.auth.Guardian) } is needed later.
*
* @param owner the owner of the dialog, normaly the main pane.
* @param mainFrame a swing frame to be displayed.
* @return the created and visible controller of the screen.
*/
private LoginScreenController createAndShowFirstLoginScreen(Stage owner, JFrame mainFrame) {
FXMLLoader loader = new FXMLLoader(LoginScreenController.class.getResource("LoginScreenView.fxml"));
Parent loginView;
try {
loginView = loader.load();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
LoginScreenController loginController = loader.getController();
Stage loginStage = new Stage();
loginStage.initModality(Modality.APPLICATION_MODAL);
loginStage.initOwner(owner);
loginStage.setScene(new Scene(loginView));
loginStage.setOnCloseRequest(e -> loginController.closed());
loginStage.show();
loginController.accept(new LoginScreenConfiguration.Builder().onSuccess(p -> {
java.awt.EventQueue.invokeLater(() -> mainFrame.setVisible(true));
Platform.runLater(() -> {
loginStage.close();
owner.close();
});
// If saft in JavaFx mode, this is enought
// Platform.runLater(() -> loginStage.close());
// Restart the timer. Instance will not be null at that time.
instance.select(LoggedInTimeoutManager.class).get().startTime();
}).onCancel(() -> System.exit(0)).build());
return loginController;
}
use of javax.enterprise.inject.Instance in project automatiko-engine by automatiko-io.
the class ProcessInstanceManagementResource method getInstance.
@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Process instance details", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Returns process instance details for given instance id")
@SuppressWarnings("unchecked")
@GET
@Path("/{processId}/instances/{instanceId}")
@Produces(MediaType.APPLICATION_JSON)
public ProcessInstanceDetailsDTO getInstance(@Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @Parameter(description = "Unique identifier of the instance", required = true) @PathParam("instanceId") String instanceId, @Parameter(description = "Status of the process instance", required = false, schema = @Schema(enumeration = { "active", "completed", "aborted", "error" })) @QueryParam("status") @DefaultValue("active") final String status, @Parameter(description = "User identifier as alternative autroization info", required = false, hidden = true) @QueryParam("user") final String user, @Parameter(description = "Groups as alternative autroization info", required = false, hidden = true) @QueryParam("group") final List<String> groups) {
try {
identitySupplier.buildIdentityProvider(user, groups);
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
Process<?> process = processData.get(processId);
Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(instanceId, mapStatus(status), ProcessInstanceReadMode.READ_ONLY);
if (instance.isEmpty()) {
throw new ProcessInstanceNotFoundException(instanceId);
}
ProcessInstance<?> pi = instance.get();
ProcessInstanceDetailsDTO details = new ProcessInstanceDetailsDTO();
String id = pi.id();
if (pi.parentProcessInstanceId() != null) {
id = pi.parentProcessInstanceId() + ":" + id;
}
details.setId(id);
details.setProcessId(processId);
details.setBusinessKey(pi.businessKey() == null ? "" : pi.businessKey());
details.setDescription(pi.description());
details.setState(pi.status());
details.setFailed(pi.errors().isPresent());
if (pi.errors().isPresent()) {
details.setErrors(pi.errors().get().errors().stream().map(e -> new ErrorInfoDTO(e.failedNodeId(), e.errorId(), e.errorMessage(), e.errorDetails())).collect(Collectors.toList()));
}
details.setImage((serviceUrl == null ? "" : serviceUrl) + "/management/processes/" + processId + "/instances/" + instanceId + "/image?status=" + reverseMapStatus(pi.status()));
details.setTags(pi.tags().values());
details.setVariables(pi.variables());
details.setSubprocesses(pi.subprocesses().stream().map(spi -> new ProcessInstanceDTO(spi.id(), spi.businessKey(), spi.description(), spi.tags().values(), spi.errors().isPresent(), spi.process().id(), spi.status())).collect(Collectors.toList()));
VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) process).process()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
details.setVersionedVariables(variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(v -> v.getName()).collect(Collectors.toList()));
return details;
});
} finally {
IdentityProvider.set(null);
}
}
use of javax.enterprise.inject.Instance in project automatiko-engine by automatiko-io.
the class ProcessInstanceManagementResource method importInstance.
@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given process id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Exported process instance", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Imports exported process instance and returns its details after the import")
@POST
@Path("/{processId}/instances")
@Produces(MediaType.APPLICATION_JSON)
public ProcessInstanceDetailsDTO importInstance(@Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @Parameter(description = "User identifier as alternative autroization info", required = false, hidden = true) @QueryParam("user") final String user, @Parameter(description = "Groups as alternative autroization info", required = false, hidden = true) @QueryParam("group") final List<String> groups, @Parameter(description = "The input model for orders instance", schema = @Schema(type = SchemaType.OBJECT, implementation = Map.class)) JsonExportedProcessInstance instance) {
identitySupplier.buildIdentityProvider(user, groups);
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<?> pi = exporter.importInstance(instance);
ProcessInstanceDetailsDTO details = new ProcessInstanceDetailsDTO();
details.setId(pi.id());
details.setProcessId(processId);
details.setBusinessKey(pi.businessKey());
details.setDescription(pi.description());
details.setFailed(pi.errors().isPresent());
if (pi.errors().isPresent()) {
details.setErrors(pi.errors().get().errors().stream().map(e -> new ErrorInfoDTO(e.failedNodeId(), e.errorId(), e.errorMessage(), e.errorDetails())).collect(Collectors.toList()));
}
details.setImage((serviceUrl == null ? "" : serviceUrl) + "/management/processes/" + processId + "/instances/" + pi.id() + "/image");
details.setTags(pi.tags().values());
details.setVariables(pi.variables());
VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) pi.process()).process()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
details.setVersionedVariables(variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(v -> v.getName()).collect(Collectors.toList()));
return details;
});
}
use of javax.enterprise.inject.Instance in project quarkus by quarkusio.
the class QuarkusJaegerTracerTest method withzipkinCompatibilityMode.
@Test
@SuppressWarnings("unchecked")
public void withzipkinCompatibilityMode() {
try (MockedStatic<Configuration> mockedStaticConfiguration = Mockito.mockStatic(Configuration.class);
MockedStatic<CDI> mockedStaticCDI = Mockito.mockStatic(CDI.class)) {
CDI<Object> mockedCDI = (CDI<Object>) Mockito.mock(CDI.class);
mockedStaticCDI.when(() -> CDI.current()).thenReturn(mockedCDI);
Instance instanceCDI = Mockito.mock(Instance.class);
Mockito.when(instanceCDI.isAmbiguous()).thenReturn(false);
Mockito.when(instanceCDI.isUnsatisfied()).thenReturn(false);
Mockito.when(instanceCDI.get()).thenReturn(new ZipkinReporterFactoryImpl());
Mockito.when(mockedCDI.select(ReporterFactory.class, Default.Literal.INSTANCE)).thenReturn(instanceCDI);
Configuration mockedInstanceConfiguration = Mockito.mock(Configuration.class);
Builder mockedBuilder = Mockito.mock(Builder.class);
Tracer mockedTracer = Mockito.mock(JaegerTracer.class);
mockedStaticConfiguration.when(() -> Configuration.fromEnv()).thenReturn(mockedInstanceConfiguration);
mockedStaticConfiguration.when(() -> mockedInstanceConfiguration.withMetricsFactory(Mockito.any())).thenReturn(mockedInstanceConfiguration);
mockedStaticConfiguration.when(() -> mockedInstanceConfiguration.getTracerBuilder()).thenReturn(mockedBuilder);
mockedStaticConfiguration.when(() -> mockedBuilder.withScopeManager(Mockito.any())).thenReturn(mockedBuilder);
mockedStaticConfiguration.when(() -> mockedBuilder.withReporter(Mockito.any())).thenReturn(mockedBuilder);
mockedStaticConfiguration.when(() -> mockedBuilder.build()).thenReturn(mockedTracer);
QuarkusJaegerTracer tracer = new QuarkusJaegerTracer();
tracer.setZipkinCompatibilityMode(true);
tracer.setEndpoint("http://localhost");
tracer.toString();
tracer.close();
ArgumentCaptor<Reporter> argument = ArgumentCaptor.forClass(Reporter.class);
Mockito.verify(mockedBuilder).withReporter(argument.capture());
assertEquals(ZipkinV2Reporter.class, argument.getValue().getClass());
}
}
Aggregations