Search in sources :

Example 26 with Instance

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();
    }
}
Also used : EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene) UserInfoException(eu.ggnet.dwoss.core.common.UserInfoException) ParameterException(com.beust.jcommander.ParameterException) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) StackPane(javafx.scene.layout.StackPane) eu.ggnet.dwoss.assembly.client.support(eu.ggnet.dwoss.assembly.client.support) JFXPanel(javafx.embed.swing.JFXPanel) DossierFilterView(eu.ggnet.dwoss.redtapext.ui.dbs.DossierFilterView) Application(javafx.application.Application) Parent(javafx.scene.Parent) RedTapeView(eu.ggnet.dwoss.redtapext.ui.cao.RedTapeView) FXMLLoader(javafx.fxml.FXMLLoader) MonitorManager(eu.ggnet.dwoss.assembly.client.support.monitor.MonitorManager) ImageIcon(javax.swing.ImageIcon) Dl(eu.ggnet.dwoss.core.widget.Dl) eu.ggnet.dwoss.assembly.client.support.exception(eu.ggnet.dwoss.assembly.client.support.exception) JFrame(javax.swing.JFrame) Instance(javax.enterprise.inject.Instance) Pane(javafx.scene.layout.Pane) Alert(javafx.scene.control.Alert) Modality(javafx.stage.Modality) Label(javafx.scene.control.Label) javafx.scene.input(javafx.scene.input) Logger(org.slf4j.Logger) SeContainerInitializer(javax.enterprise.inject.se.SeContainerInitializer) RemoteLookup(eu.ggnet.dwoss.core.widget.dl.RemoteLookup) CachedMandators(eu.ggnet.dwoss.mandator.spi.CachedMandators) eu.ggnet.dwoss.assembly.client.support.login(eu.ggnet.dwoss.assembly.client.support.login) Swing(eu.ggnet.saft.core.impl.Swing) JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException) WindowAdapter(java.awt.event.WindowAdapter) SearchCask(eu.ggnet.dwoss.search.ui.SearchCask) WindowEvent(java.awt.event.WindowEvent) StandardCharsets(java.nio.charset.StandardCharsets) EventType(javafx.event.EventType) Platform(javafx.application.Platform) Saft(eu.ggnet.saft.core.Saft) ConstraintViolationException(javax.validation.ConstraintViolationException) Stage(javafx.stage.Stage) Guardian(eu.ggnet.dwoss.core.widget.auth.Guardian) UiCore(eu.ggnet.saft.core.UiCore) SeContainer(javax.enterprise.inject.se.SeContainer) Optional(java.util.Optional) RawReportView(eu.ggnet.dwoss.report.ui.RawReportView) JFrame(javax.swing.JFrame) Guardian(eu.ggnet.dwoss.core.widget.auth.Guardian) ParameterException(com.beust.jcommander.ParameterException) Alert(javafx.scene.control.Alert)

Example 27 with Instance

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;
}
Also used : EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene) UserInfoException(eu.ggnet.dwoss.core.common.UserInfoException) ParameterException(com.beust.jcommander.ParameterException) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) StackPane(javafx.scene.layout.StackPane) eu.ggnet.dwoss.assembly.client.support(eu.ggnet.dwoss.assembly.client.support) JFXPanel(javafx.embed.swing.JFXPanel) DossierFilterView(eu.ggnet.dwoss.redtapext.ui.dbs.DossierFilterView) Application(javafx.application.Application) Parent(javafx.scene.Parent) RedTapeView(eu.ggnet.dwoss.redtapext.ui.cao.RedTapeView) FXMLLoader(javafx.fxml.FXMLLoader) MonitorManager(eu.ggnet.dwoss.assembly.client.support.monitor.MonitorManager) ImageIcon(javax.swing.ImageIcon) Dl(eu.ggnet.dwoss.core.widget.Dl) eu.ggnet.dwoss.assembly.client.support.exception(eu.ggnet.dwoss.assembly.client.support.exception) JFrame(javax.swing.JFrame) Instance(javax.enterprise.inject.Instance) Pane(javafx.scene.layout.Pane) Alert(javafx.scene.control.Alert) Modality(javafx.stage.Modality) Label(javafx.scene.control.Label) javafx.scene.input(javafx.scene.input) Logger(org.slf4j.Logger) SeContainerInitializer(javax.enterprise.inject.se.SeContainerInitializer) RemoteLookup(eu.ggnet.dwoss.core.widget.dl.RemoteLookup) CachedMandators(eu.ggnet.dwoss.mandator.spi.CachedMandators) eu.ggnet.dwoss.assembly.client.support.login(eu.ggnet.dwoss.assembly.client.support.login) Swing(eu.ggnet.saft.core.impl.Swing) JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException) WindowAdapter(java.awt.event.WindowAdapter) SearchCask(eu.ggnet.dwoss.search.ui.SearchCask) WindowEvent(java.awt.event.WindowEvent) StandardCharsets(java.nio.charset.StandardCharsets) EventType(javafx.event.EventType) Platform(javafx.application.Platform) Saft(eu.ggnet.saft.core.Saft) ConstraintViolationException(javax.validation.ConstraintViolationException) Stage(javafx.stage.Stage) Guardian(eu.ggnet.dwoss.core.widget.auth.Guardian) UiCore(eu.ggnet.saft.core.UiCore) SeContainer(javax.enterprise.inject.se.SeContainer) Optional(java.util.Optional) RawReportView(eu.ggnet.dwoss.report.ui.RawReportView) Parent(javafx.scene.Parent) Stage(javafx.stage.Stage) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader)

Example 28 with Instance

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);
    }
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ProcessInstanceExporter(io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter) MediaType(javax.ws.rs.core.MediaType) Application(io.automatiko.engine.api.Application) QueryParam(javax.ws.rs.QueryParam) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) SchemaType(org.eclipse.microprofile.openapi.annotations.enums.SchemaType) VariableNotFoundException(io.automatiko.engine.api.workflow.VariableNotFoundException) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Instance(javax.enterprise.inject.Instance) DELETE(javax.ws.rs.DELETE) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) IoUtils(io.automatiko.engine.services.utils.IoUtils) Model(io.automatiko.engine.api.Model) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Operation(org.eclipse.microprofile.openapi.annotations.Operation) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) Parameter(org.eclipse.microprofile.openapi.annotations.parameters.Parameter) ProcessInstanceDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Optional(java.util.Optional) Tag(org.eclipse.microprofile.openapi.annotations.tags.Tag) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) PathParam(javax.ws.rs.PathParam) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) IdentitySupplier(io.automatiko.engine.api.auth.IdentitySupplier) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.workflow.Process) ProcessDTO(io.automatiko.engine.addons.process.management.model.ProcessDTO) Content(org.eclipse.microprofile.openapi.annotations.media.Content) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UnitOfWorkExecutor(io.automatiko.engine.services.uow.UnitOfWorkExecutor) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Schema(org.eclipse.microprofile.openapi.annotations.media.Schema) IOException(java.io.IOException) ExternalDocumentation(org.eclipse.microprofile.openapi.annotations.ExternalDocumentation) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Collections(java.util.Collections) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) Optional(java.util.Optional) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) ProcessInstanceDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 29 with Instance

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;
    });
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ProcessInstanceExporter(io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter) MediaType(javax.ws.rs.core.MediaType) Application(io.automatiko.engine.api.Application) QueryParam(javax.ws.rs.QueryParam) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) SchemaType(org.eclipse.microprofile.openapi.annotations.enums.SchemaType) VariableNotFoundException(io.automatiko.engine.api.workflow.VariableNotFoundException) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Instance(javax.enterprise.inject.Instance) DELETE(javax.ws.rs.DELETE) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) IoUtils(io.automatiko.engine.services.utils.IoUtils) Model(io.automatiko.engine.api.Model) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Operation(org.eclipse.microprofile.openapi.annotations.Operation) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) Parameter(org.eclipse.microprofile.openapi.annotations.parameters.Parameter) ProcessInstanceDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Optional(java.util.Optional) Tag(org.eclipse.microprofile.openapi.annotations.tags.Tag) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) PathParam(javax.ws.rs.PathParam) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) IdentitySupplier(io.automatiko.engine.api.auth.IdentitySupplier) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.workflow.Process) ProcessDTO(io.automatiko.engine.addons.process.management.model.ProcessDTO) Content(org.eclipse.microprofile.openapi.annotations.media.Content) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UnitOfWorkExecutor(io.automatiko.engine.services.uow.UnitOfWorkExecutor) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Schema(org.eclipse.microprofile.openapi.annotations.media.Schema) IOException(java.io.IOException) ExternalDocumentation(org.eclipse.microprofile.openapi.annotations.ExternalDocumentation) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Collections(java.util.Collections) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 30 with Instance

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());
    }
}
Also used : Configuration(io.jaegertracing.Configuration) Instance(javax.enterprise.inject.Instance) Tracer(io.opentracing.Tracer) QuarkusJaegerTracer(io.quarkus.jaeger.runtime.QuarkusJaegerTracer) JaegerTracer(io.jaegertracing.internal.JaegerTracer) QuarkusJaegerTracer(io.quarkus.jaeger.runtime.QuarkusJaegerTracer) Builder(io.jaegertracing.internal.JaegerTracer.Builder) ZipkinV2Reporter(io.jaegertracing.zipkin.ZipkinV2Reporter) Reporter(io.jaegertracing.spi.Reporter) CDI(javax.enterprise.inject.spi.CDI) ZipkinReporterFactoryImpl(io.quarkus.jaeger.runtime.ZipkinReporterFactoryImpl) Test(org.junit.jupiter.api.Test)

Aggregations

Instance (javax.enterprise.inject.Instance)41 Test (org.junit.Test)14 List (java.util.List)12 Inject (javax.inject.Inject)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 Optional (java.util.Optional)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 IOException (java.io.IOException)5 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)4 Path (javax.ws.rs.Path)4 MediaType (javax.ws.rs.core.MediaType)4 ProcessInstanceExporter (io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter)3 ErrorInfoDTO (io.automatiko.engine.addons.process.management.model.ErrorInfoDTO)3 JsonExportedProcessInstance (io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance)3 ProcessDTO (io.automatiko.engine.addons.process.management.model.ProcessDTO)3 ProcessInstanceDTO (io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO)3