Search in sources :

Example 6 with Instance

use of javax.enterprise.inject.Instance in project ART-TIME by Artezio.

the class TrackingSystemProducerTest method getTeamTrackingSystemNames.

@Test
public void getTeamTrackingSystemNames() throws NoSuchFieldException {
    Instance instance = createMock(Instance.class);
    trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).addMockedMethod("getTrackingSystemsNames", Instance.class).createMock();
    setField(trackingSystemProducer, "teamTrackingSystems", instance);
    Set<String> expected = Sets.newHashSet("A", "B");
    expect(trackingSystemProducer.getTrackingSystemsNames(instance)).andReturn(expected);
    replayAll(instance, trackingSystemProducer);
    Set<String> actual = trackingSystemProducer.getTeamTrackingSystemNames();
    verifyAll();
    assertEquals(expected, actual);
}
Also used : Instance(javax.enterprise.inject.Instance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with Instance

use of javax.enterprise.inject.Instance in project kernel by exoplatform.

the class WeldContainer method getComponentAdapter.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public <T> ComponentAdapter<T> getComponentAdapter(final Object componentKey, Class<T> bindType, boolean autoRegistration) {
    ComponentAdapter<T> result = super.getComponentAdapter(componentKey, bindType, autoRegistration);
    if (weld != null && result == null) {
        if (componentKey instanceof Class<?> && !((Class<?>) componentKey).isAnnotation()) {
            return getAdapterOfType((Class<T>) componentKey);
        } else if (componentKey instanceof String) {
            Set<Bean<?>> beans = container.getBeanManager().getBeans(bindType, createNamed((String) componentKey));
            if (beans != null && !beans.isEmpty()) {
                return createComponentAdapter(bindType, (Instance<T>) container.instance().select(beans.iterator().next().getBeanClass()));
            }
        } else if (componentKey instanceof Class<?>) {
            final Class<? extends Annotation> annotationType = (Class<? extends Annotation>) componentKey;
            Annotation annotation = createAnnotation(annotationType);
            Set<Bean<?>> beans = container.getBeanManager().getBeans(bindType, annotation);
            if (beans != null && !beans.isEmpty()) {
                return createComponentAdapter(bindType, (Instance<T>) container.instance().select(beans.iterator().next().getBeanClass()));
            }
        }
    }
    return result;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Instance(javax.enterprise.inject.Instance) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean)

Example 8 with Instance

use of javax.enterprise.inject.Instance in project dwoss by gg-net.

the class SalesListingCreateMenuItemProducer method createMenuItems.

/**
 * Produces all Menuitems, wrapped into one instance, either using the Remote implementation of
 * {@link ListingActionService}, if existing, or creating some defaults.
 *
 * @return all Menuitems, wrapped into one instance.
 */
@Produces
public SalesListingCreateMenus createMenuItems() {
    List<SalesListingCreateMenuItem> items = new ArrayList<>();
    if (Dl.remote().contains(ListingActionService.class)) {
        Map<ListingActionConfiguration.Location, List<ListingActionConfiguration>> actionConfigs = Dl.remote().lookup(ListingActionService.class).listingActionConfigurations().stream().collect(Collectors.groupingBy(conf -> conf.location));
        if (actionConfigs != null && !actionConfigs.isEmpty()) {
            for (List<ListingActionConfiguration> listingActionConfigurations : actionConfigs.values()) {
                for (ListingActionConfiguration listingActionConfiguration : listingActionConfigurations) {
                    SalesListingCreateMenuItem item = instances.select().get();
                    item.setConfig(listingActionConfiguration);
                    items.add(item);
                }
            }
        }
    } else {
        SalesListingCreateMenuItem item = instances.select().get();
        item.setConfig(new ListingActionConfiguration(Type.XLS, Location.LOCAL, SalesChannel.RETAILER, "XLS für Händler"));
        items.add(item);
        item = instances.select().get();
        item.setConfig(new ListingActionConfiguration(Type.XLS, Location.LOCAL, SalesChannel.CUSTOMER, "XLS für Endkunden"));
        items.add(item);
        item = instances.select().get();
        item.setConfig(new ListingActionConfiguration(Type.PDF, Location.LOCAL, SalesChannel.RETAILER, "PDF für Händler"));
        items.add(item);
        item = instances.select().get();
        item.setConfig(new ListingActionConfiguration(Type.PDF, Location.LOCAL, SalesChannel.CUSTOMER, "PDF für Endkunden"));
        items.add(item);
    }
    return new SalesListingCreateMenus(items);
}
Also used : Inject(javax.inject.Inject) ListingActionConfiguration(eu.ggnet.dwoss.mandator.api.service.ListingActionConfiguration) java.util(java.util) Produces(javax.enterprise.inject.Produces) Type(eu.ggnet.dwoss.mandator.api.service.ListingActionConfiguration.Type) Location(eu.ggnet.dwoss.mandator.api.service.ListingActionConfiguration.Location) Dl(eu.ggnet.dwoss.core.widget.Dl) ListingActionService(eu.ggnet.dwoss.mandator.api.service.ListingActionService) Collectors(java.util.stream.Collectors) SalesChannel(eu.ggnet.dwoss.core.common.values.SalesChannel) Instance(javax.enterprise.inject.Instance) ListingActionConfiguration(eu.ggnet.dwoss.mandator.api.service.ListingActionConfiguration) ListingActionService(eu.ggnet.dwoss.mandator.api.service.ListingActionService) Location(eu.ggnet.dwoss.mandator.api.service.ListingActionConfiguration.Location) Produces(javax.enterprise.inject.Produces)

Example 9 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(@Context UriInfo uriInfo, @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(uriInfo.getBaseUri().toString() + "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) Context(javax.ws.rs.core.Context) 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) UriInfo(javax.ws.rs.core.UriInfo) 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) 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 10 with Instance

use of javax.enterprise.inject.Instance in project smallrye-config by smallrye.

the class ConfigExtension method registerCustomBeans.

protected void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    Set<Class<?>> customTypes = new HashSet<>();
    for (InjectionPoint ip : configPropertyInjectionPoints) {
        Type requiredType = ip.getType();
        if (requiredType instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType) requiredType;
            // TODO We should probably handle all parameterized types correctly
            if (type.getRawType().equals(Provider.class) || type.getRawType().equals(Instance.class)) {
                // These injection points are satisfied by the built-in Instance bean
                Type typeArgument = type.getActualTypeArguments()[0];
                if (typeArgument instanceof Class && !isClassHandledByConfigProducer(typeArgument)) {
                    customTypes.add((Class<?>) typeArgument);
                }
            }
        } else if (requiredType instanceof Class && !isClassHandledByConfigProducer(requiredType)) {
            // type is not produced by ConfigProducer
            customTypes.add((Class<?>) requiredType);
        }
    }
    customTypes.stream().map(customType -> new ConfigInjectionBean<>(bm, customType)).forEach(abd::addBean);
    configProperties.stream().map(annotatedType -> new ConfigMappingInjectionBean<>(bm, annotatedType)).forEach(abd::addBean);
    configMappings.stream().map(annotatedType -> new ConfigMappingInjectionBean<>(bm, annotatedType)).forEach(abd::addBean);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ConfigMappings.registerConfigMappings(io.smallrye.config.ConfigMappings.registerConfigMappings) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) Provider(javax.inject.Provider) OptionalDouble(java.util.OptionalDouble) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) BeforeBeanDiscovery(javax.enterprise.inject.spi.BeforeBeanDiscovery) ConfigMappings.registerConfigProperties(io.smallrye.config.ConfigMappings.registerConfigProperties) Map(java.util.Map) Observes(javax.enterprise.event.Observes) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) ConfigClassWithPrefix.configClassWithPrefix(io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix) StreamSupport(java.util.stream.StreamSupport) Collectors.toSet(java.util.stream.Collectors.toSet) Instance(javax.enterprise.inject.Instance) ConfigProperties(org.eclipse.microprofile.config.inject.ConfigProperties) ConfigMappingInjectionBean.getPrefixFromType(io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromType) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) Extension(javax.enterprise.inject.spi.Extension) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ConfigMappingInjectionBean.getPrefixFromInjectionPoint(io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromInjectionPoint) Set(java.util.Set) WithAnnotations(javax.enterprise.inject.spi.WithAnnotations) Config(org.eclipse.microprofile.config.Config) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) ConfigMapping(io.smallrye.config.ConfigMapping) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) SecuritySupport.getContextClassLoader(io.smallrye.config.inject.SecuritySupport.getContextClassLoader) Type(java.lang.reflect.Type) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ConfigValidationException(io.smallrye.config.ConfigValidationException) ConfigProducer.isClassHandledByConfigProducer(io.smallrye.config.inject.ConfigProducer.isClassHandledByConfigProducer) InjectionMessages.formatInjectionPoint(io.smallrye.config.inject.InjectionMessages.formatInjectionPoint) Optional(java.util.Optional) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) ConfigClassWithPrefix(io.smallrye.config.ConfigMappings.ConfigClassWithPrefix) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManager(javax.enterprise.inject.spi.BeanManager) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) ConfigMappingInjectionBean.getPrefixFromType(io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) ConfigMappingInjectionBean.getPrefixFromInjectionPoint(io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromInjectionPoint) InjectionMessages.formatInjectionPoint(io.smallrye.config.inject.InjectionMessages.formatInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Instance(javax.enterprise.inject.Instance) HashSet(java.util.HashSet) Provider(javax.inject.Provider) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider)

Aggregations

Instance (javax.enterprise.inject.Instance)28 Test (org.junit.Test)13 List (java.util.List)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Optional (java.util.Optional)8 Inject (javax.inject.Inject)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Settings (com.artezio.arttime.config.Settings)3 Dl (eu.ggnet.dwoss.core.widget.Dl)3 IOException (java.io.IOException)3 JCommander (com.beust.jcommander.JCommander)2 ParameterException (com.beust.jcommander.ParameterException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 eu.ggnet.dwoss.assembly.client.support (eu.ggnet.dwoss.assembly.client.support)2 eu.ggnet.dwoss.assembly.client.support.exception (eu.ggnet.dwoss.assembly.client.support.exception)2