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);
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations