javax.enterprise.util.AnnotationLiteral Java Examples

The following examples show how to use javax.enterprise.util.AnnotationLiteral. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceProviderDiscovery.java    From joynr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("serial")
public Set<Bean<?>> findServiceProviderBeans() {
    Set<Bean<?>> result = new HashSet<>();
    for (Bean<?> bean : beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
    })) {
        ServiceProvider serviceProvider = bean.getBeanClass().getAnnotation(ServiceProvider.class);
        if (serviceProvider != null) {
            ProvidedBy providedBy = getProvidedByAnnotation(serviceProvider.serviceInterface());
            verifyProvidedBy(providedBy, serviceProvider.serviceInterface(), bean);
            result.add(bean);
            if (logger.isTraceEnabled()) {
                logger.trace(format("Bean %s is a service provider. Adding to result.", bean));
            }
        } else if (logger.isTraceEnabled()) {
            logger.trace(format("Ignoring bean: %s", bean));
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(format("Found the following service provider beans:%n%s", result));
    }
    return result;
}
 
Example #2
Source File: DocumentManagerBean.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID)
@Override
public DocumentRevision removeTag(DocumentRevisionKey pDocRPK, String pTag)
        throws UserNotFoundException, WorkspaceNotFoundException, UserNotActiveException, AccessRightException, DocumentRevisionNotFoundException, NotAllowedException, WorkspaceNotEnabledException {

    User user = checkDocumentRevisionWriteAccess(pDocRPK);

    DocumentRevision docR = getDocumentRevision(pDocRPK);
    Tag tagToRemove = new Tag(user.getWorkspace(), pTag);
    docR.getTags().remove(tagToRemove);

    tagEvent.select(new AnnotationLiteral<Untagged>() {
    }).fire(new TagEvent(tagToRemove, docR));

    if (isCheckoutByAnotherUser(user, docR)) {
        em.detach(docR);
        docR.removeLastIteration();
    }

    docR.getDocumentIterations().forEach(indexerManager::indexDocumentIteration);
    return docR;
}
 
Example #3
Source File: DocumentManagerBean.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID)
@Override
public void deleteTag(TagKey pKey) throws WorkspaceNotFoundException, AccessRightException, TagNotFoundException, UserNotFoundException, WorkspaceNotEnabledException {
    User user = userManager.checkWorkspaceWriteAccess(pKey.getWorkspace());
    Tag tagToRemove = new Tag(user.getWorkspace(), pKey.getLabel());
    List<DocumentRevision> docRs = documentRevisionDAO.findDocRsByTag(tagToRemove);
    for (DocumentRevision docR : docRs) {
        docR.getTags().remove(tagToRemove);
    }
    List<ChangeItem> changeItems = changeItemDAO.findChangeItemByTag(pKey.getWorkspace(), tagToRemove);
    for (ChangeItem changeItem : changeItems) {
        changeItem.getTags().remove(tagToRemove);
    }

    List<PartRevision> partRevisions = partRevisionDAO.findPartByTag(tagToRemove);
    for (PartRevision partRevision : partRevisions) {
        partRevision.getTags().remove(tagToRemove);
    }

    tagEvent.select(new AnnotationLiteral<Removed>() {
    }).fire(new TagEvent(tagToRemove));

    tagDAO.removeTag(pKey);
}
 
Example #4
Source File: UserManagerBean.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID})
@Override
public User checkWorkspaceReadAccess(String pWorkspaceId) throws UserNotFoundException, UserNotActiveException, WorkspaceNotFoundException, WorkspaceNotEnabledException {
    String login = contextManager.getCallerPrincipalLogin();
    WorkspaceUserMembership userMS = userDAO.loadUserMembership(new WorkspaceUserMembershipKey(pWorkspaceId, pWorkspaceId, login));
    Workspace wks = workspaceDAO.loadWorkspace(pWorkspaceId);
    User user = userDAO.loadUser(new UserKey(pWorkspaceId, login));

    if (!wks.isEnabled()) {
        throw new WorkspaceNotEnabledException(pWorkspaceId);
    } else if (userMS != null) {
        user = userMS.getMember();
    } else if (!wks.getAdmin().getLogin().equals(login)) {
        WorkspaceUserGroupMembership[] groupMS = userGroupDAO.getUserGroupMemberships(pWorkspaceId, user);
        if (groupMS.length == 0) {
            throw new UserNotActiveException(login);
        }
    }

    workspaceAccessEvent.select(new AnnotationLiteral<Read>() {
    }).fire(new WorkspaceAccessEvent(user));

    return user;
}
 
Example #5
Source File: ProductManagerBean.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID)
@Override
public PartRevision removeTag(PartRevisionKey partRevisionKey, String tagName) throws UserNotFoundException, WorkspaceNotFoundException, UserNotActiveException, PartRevisionNotFoundException, AccessRightException, WorkspaceNotEnabledException {
    User user = checkPartRevisionWriteAccess(partRevisionKey);

    PartRevision partRevision = getPartRevision(partRevisionKey);
    Tag tagToRemove = new Tag(user.getWorkspace(), tagName);
    partRevision.getTags().remove(tagToRemove);

    tagEvent.select(new AnnotationLiteral<Untagged>() {
    }).fire(new TagEvent(tagToRemove, partRevision));

    if (isCheckoutByAnotherUser(user, partRevision)) {
        em.detach(partRevision);
        partRevision.removeLastIteration();
    }

    partRevision.getPartIterations().forEach(indexerManager::indexPartIteration);

    return partRevision;
}
 
Example #6
Source File: ServiceProviderDiscoveryTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testWrongServiceInterfaceSpecified() {
    BeanManager mockBeanManager = mock(BeanManager.class);

    Bean<DummyBeanOne> mockBeanOne = mock(Bean.class);
    Mockito.doReturn(DummyBeanOne.class).when(mockBeanOne).getBeanClass();
    Bean<DummyBeanFour> mockBeanFour = mock(Bean.class);
    Mockito.doReturn(DummyBeanFour.class).when(mockBeanFour).getBeanClass();

    Set<Bean<?>> beans = new HashSet<>();
    beans.add(mockBeanOne);
    beans.add(mockBeanFour);
    Mockito.when(mockBeanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
    })).thenReturn(beans);

    ServiceProviderDiscovery subject = new ServiceProviderDiscovery(mockBeanManager);

    subject.findServiceProviderBeans();
    fail("Shouldn't be able to get here with an invalid bean (DummyBeanFour)");
}
 
Example #7
Source File: ServiceProviderDiscoveryTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testInvalidServiceInterfaceSpecified() {
    BeanManager mockBeanManager = mock(BeanManager.class);

    Bean<DummyBeanOne> mockBeanOne = mock(Bean.class);
    Mockito.doReturn(DummyBeanOne.class).when(mockBeanOne).getBeanClass();
    Bean<DummyBeanFour> mockBeanThree = mock(Bean.class);
    Mockito.doReturn(DummyBeanThree.class).when(mockBeanThree).getBeanClass();

    Set<Bean<?>> beans = new HashSet<>();
    beans.add(mockBeanOne);
    beans.add(mockBeanThree);
    Mockito.when(mockBeanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
    })).thenReturn(beans);

    ServiceProviderDiscovery subject = new ServiceProviderDiscovery(mockBeanManager);

    subject.findServiceProviderBeans();
    fail("Shouldn't be able to get here with an invalid bean (DummyBeanThree)");
}
 
Example #8
Source File: MakeJCacheCDIInterceptorFriendly.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
public HelperBean(final AnnotatedType<CDIJCacheHelper> annotatedType,
                  final InjectionTarget<CDIJCacheHelper> injectionTarget,
                  final String id) {
    this.at = annotatedType;
    this.it = injectionTarget;
    this.id =  "JCS#CDIHelper#" + id;

    this.qualifiers = new HashSet<>();
    this.qualifiers.add(new AnnotationLiteral<Default>() {

        /**
         * 
         */
        private static final long serialVersionUID = 3314657767813459983L;});
    this.qualifiers.add(new AnnotationLiteral<Any>() {

        /**
         * 
         */
        private static final long serialVersionUID = 7419841275942488170L;});
}
 
Example #9
Source File: ServiceProviderDiscoveryTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "serial" })
@Test
public void testFindServiceProviderBeans() {
    BeanManager mockBeanManager = mock(BeanManager.class);

    Bean<DummyBeanOne> mockBeanOne = mock(Bean.class);
    Mockito.doReturn(DummyBeanOne.class).when(mockBeanOne).getBeanClass();
    Bean<DummyBeanTwo> mockBeanTwo = mock(Bean.class);
    Mockito.doReturn(DummyBeanTwo.class).when(mockBeanTwo).getBeanClass();

    Set<Bean<?>> beans = new HashSet<>();
    beans.add(mockBeanOne);
    beans.add(mockBeanTwo);
    Mockito.when(mockBeanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
    })).thenReturn(beans);

    ServiceProviderDiscovery subject = new ServiceProviderDiscovery(mockBeanManager);

    Set<Bean<?>> result = subject.findServiceProviderBeans();

    assertNotNull(result);
    assertEquals(1, result.size());
    assertTrue(result.iterator().next().getBeanClass().equals(DummyBeanOne.class));
}
 
Example #10
Source File: DefaultJoynrRuntimeFactory.java    From joynr with Apache License 2.0 6 votes vote down vote up
private <T> AbstractModule getModuleForBeansOfType(Class<T> beanType,
                                                   Supplier<TypeLiteral<T>> typeLiteralSupplier) {
    final Set<Bean<?>> beans = beanManager.getBeans(beanType, new AnnotationLiteral<Any>() {
        private static final long serialVersionUID = 1L;
    });
    return new AbstractModule() {
        @SuppressWarnings("unchecked")
        @Override
        protected void configure() {

            Multibinder<T> beanMultibinder = Multibinder.newSetBinder(binder(), typeLiteralSupplier.get());
            for (Bean<?> bean : beans) {
                beanMultibinder.addBinding()
                               .toInstance((T) Proxy.newProxyInstance(getClass().getClassLoader(),
                                                                      new Class[]{ beanType },
                                                                      new BeanCallingProxy<T>((Bean<T>) bean,
                                                                                              beanManager)));
            }
        }
    };
}
 
Example #11
Source File: CallbackHandlerDiscovery.java    From joynr with Apache License 2.0 6 votes vote down vote up
public void forEach(Consumer<StatelessAsyncCallback> consumer) {
    Set<Bean<?>> callbackHandlerBeans = beanManager.getBeans(Object.class,
                                                             new AnnotationLiteral<CallbackHandler>() {
                                                             });
    callbackHandlerBeans.forEach(callbackHandlerBean -> {
        for (Class<?> interfaceClass : callbackHandlerBean.getBeanClass().getInterfaces()) {
            if (StatelessAsyncCallback.class.isAssignableFrom(interfaceClass)) {
                UsedBy usedBy = interfaceClass.getAnnotation(UsedBy.class);
                if (usedBy == null) {
                    logger.warn("Stateless async callback interface " + interfaceClass + " implemented by "
                            + callbackHandlerBean
                            + " is not annotated with @UsedBy. Are you using an outdated version of the joynr "
                            + "code generator without setting the 'jee' parameter to ' true'? "
                            + "Note that the 'jee' property is now deprecated.");
                    continue;
                }
                StatelessAsyncCallback beanReference = (StatelessAsyncCallback) beanManager.getReference(callbackHandlerBean,
                                                                                                         interfaceClass,
                                                                                                         beanManager.createCreationalContext(callbackHandlerBean));
                consumer.accept(beanReference);
                break;
            }
        }
    });
}
 
Example #12
Source File: BeanManagerTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("serial")
@Test
public void testResolveInterceptors() {
    BeanManager beanManager = Arc.container().beanManager();
    List<javax.enterprise.inject.spi.Interceptor<?>> interceptors;
    // InterceptionType does not match
    interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_CONSTRUCT, new DummyBinding.Literal(true, true));
    assertTrue(interceptors.isEmpty());
    // alpha is @Nonbinding
    interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, new DummyBinding.Literal(false, true),
            new AnnotationLiteral<UselessBinding>() {
            });
    assertEquals(2, interceptors.size());
    assertEquals(DummyInterceptor.class, interceptors.get(0).getBeanClass());
    assertEquals(LowPriorityInterceptor.class, interceptors.get(1).getBeanClass());
}
 
Example #13
Source File: ServiceLocator.java    From acmeair with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the services that are available for use with the description for each service. 
 * The Services are determined by looking up all of the implementations of the 
 * Customer Service interface that are using the  DataService qualifier annotation. 
 * The DataService annotation contains the service name and description information. 
 * @return Map containing a list of services available and a description of each one.
 */
public Map<String,String> getServices (){
	TreeMap<String,String> services = new TreeMap<String,String>();
	logger.fine("Getting CustomerService Impls");
   	Set<Bean<?>> beans = beanManager.getBeans(CustomerService.class,new AnnotationLiteral<Any>() {
		private static final long serialVersionUID = 1L;});
   	for (Bean<?> bean : beans) {    		
   		for (Annotation qualifer: bean.getQualifiers()){
   			if(DataService.class.getName().equalsIgnoreCase(qualifer.annotationType().getName())){
   				DataService service = (DataService) qualifer;
   				logger.fine("   name="+service.name()+" description="+service.description());
   				services.put(service.name(), service.description());
   			}
   		}
   	}    	
   	return services;
}
 
Example #14
Source File: WebContextProducer.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public CDIPortletWebContext(BeanManager beanManager, VariableValidator variableInspector, Models models,
	String lifecyclePhase, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
	ServletContext servletContext, Locale locale) {

	super(httpServletRequest, httpServletResponse, servletContext, locale);
	this.beanManager = beanManager;
	this.models = models;
	this.beanNames = new HashSet<>();

	boolean headerPhase = lifecyclePhase.equals(PortletRequest.HEADER_PHASE);
	boolean renderPhase = lifecyclePhase.equals(PortletRequest.RENDER_PHASE);
	boolean resourcePhase = lifecyclePhase.equals(PortletRequest.RESOURCE_PHASE);

	Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
			});

	for (Bean<?> bean : beans) {
		String beanName = bean.getName();

		if ((beanName != null) &&
				variableInspector.isValidName(beanName, headerPhase, renderPhase, resourcePhase)) {
			this.beanNames.add(beanName);
		}
	}
}
 
Example #15
Source File: UserManagerBean.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID})
@Override
public User checkWorkspaceWriteAccess(String pWorkspaceId) throws UserNotFoundException, WorkspaceNotFoundException, AccessRightException, WorkspaceNotEnabledException {
    String login = contextManager.getCallerPrincipalLogin();

    User user = userDAO.loadUser(new UserKey(pWorkspaceId, login));
    if (!hasWorkspaceWriteAccess(user, pWorkspaceId)) {
        throw new AccessRightException(user);
    }
    workspaceAccessEvent.select(new AnnotationLiteral<Write>() {
    }).fire(new WorkspaceAccessEvent(user));

    return user;
}
 
Example #16
Source File: JoynrIntegrationBean.java    From joynr with Apache License 2.0 5 votes vote down vote up
/**
 * A util method to find factories which provide some customized settings needed for
 * registration of joynr providers, i.e. implementations of the interface
 * {@link ProviderRegistrationSettingsFactory}.
 *
 * @return set of factories implementing the interface
 */
@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
private Set<ProviderRegistrationSettingsFactory> getProviderRegistrationSettingsFactories() {
    Set<Bean<?>> providerSettingsFactoryBeans = beanManager.getBeans(ProviderRegistrationSettingsFactory.class,
                                                                     new AnnotationLiteral<Any>() {
                                                                     });
    Set<ProviderRegistrationSettingsFactory> providerSettingsFactories = new HashSet<>();
    for (Bean providerSettingsFactoryBean : providerSettingsFactoryBeans) {
        ProviderRegistrationSettingsFactory factory = (ProviderRegistrationSettingsFactory) providerSettingsFactoryBean.create(beanManager.createCreationalContext(providerSettingsFactoryBean));
        providerSettingsFactories.add(factory);
    }
    return providerSettingsFactories;
}
 
Example #17
Source File: BeanLocator.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Object lookup(String beanName, String sessionID) {

		NGSessionScopeContext.setCurrentContext(sessionID);

		Set<Bean<?>> beans = beanManager.getBeans(beanName);

		Class beanClass = CommonUtils.beanNamesHolder.get(beanName);
		if (beans.isEmpty()) {
			beans = beanManager.getBeans(beanClass, new AnnotationLiteral<Any>() { //
			});
		}

		Bean bean = beanManager.resolve(beans);

		Class scopeAnnotationClass = bean.getScope();
		Context context;

		if (scopeAnnotationClass.equals(RequestScoped.class)) {
			context = beanManager.getContext(scopeAnnotationClass);
			if (context == null)
				return bean.create(beanManager.createCreationalContext(bean));

		} else {

			if (scopeAnnotationClass.equals(NGSessionScopeContext.class)) {
				context = NGSessionScopeContext.getINSTANCE();
			} else {
				context = beanManager.getContext(scopeAnnotationClass);
			}

		}
		CreationalContext creationalContext = beanManager.createCreationalContext(bean);
		Object reference = context.get(bean, creationalContext);

		// if(reference==null && scopeAnnotationClass.equals(RequestScoped.class)){
		// reference= bean.create(beanManager.createCreationalContext(bean));
		// }

		return reference;
	}
 
Example #18
Source File: ManagedUpnpService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void beforeShutdown(Registry registry) {
    registryShutdownEvent.select(new AnnotationLiteral<Before>() {
    }).fire(
            new RegistryShutdown()
    );
}
 
Example #19
Source File: ManagedUpnpService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void afterShutdown() {
    registryShutdownEvent.select(new AnnotationLiteral<After>() {
    }).fire(
            new RegistryShutdown()
    );
}
 
Example #20
Source File: ProductManagerBean.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID)
@Override
public PartRevision checkInPart(PartRevisionKey pPartRPK) throws PartRevisionNotFoundException, UserNotFoundException, WorkspaceNotFoundException, AccessRightException, NotAllowedException, EntityConstraintException, UserNotActiveException, PartMasterNotFoundException, WorkspaceNotEnabledException {
    User user = userManager.checkWorkspaceReadAccess(pPartRPK.getPartMaster().getWorkspace());

    PartRevision partR = partRevisionDAO.loadPartR(pPartRPK);

    if (partR.getACL() == null) {
        userManager.checkWorkspaceWriteAccess(pPartRPK.getWorkspaceId());
    }

    //Check access rights on partR
    if (!hasPartRevisionWriteAccess(user, partR)) {
        throw new AccessRightException(user);
    }

    if (isCheckoutByUser(user, partR)) {

        checkCyclicAssemblyForPartIteration(partR.getLastIteration());

        partR.setCheckOutDate(null);
        partR.setCheckOutUser(null);

        PartIteration lastIteration = partR.getLastIteration();
        lastIteration.setCheckInDate(new Date());

        indexerManager.indexPartIteration(lastIteration);

        partIterationEvent.select(new AnnotationLiteral<CheckedIn>() {
        }).fire(new PartIterationEvent(lastIteration));
        return partR;
    } else {
        throw new NotAllowedException("NotAllowedException20");
    }

}
 
Example #21
Source File: FlywayExtension.java    From tutorials with MIT License 5 votes vote down vote up
public void processAnnotatedType(@Observes ProcessAnnotatedType<Flyway> patEvent) {
    patEvent.configureAnnotatedType()
            //Add Scope
            .add(ApplicationScoped.Literal.INSTANCE)
            //Add Qualifier
            .add(new AnnotationLiteral<FlywayType>() {
            })
            //Decorate setDataSource(DataSource dataSource){} with @Inject
            .filterMethods(annotatedMethod -> {
                return annotatedMethod.getParameters().size() == 1 &&
                        annotatedMethod.getParameters().get(0).getBaseType().equals(javax.sql.DataSource.class);
            })
            .findFirst().get().add(InjectLiteral.INSTANCE);
}
 
Example #22
Source File: FlywayExtension.java    From tutorials with MIT License 5 votes vote down vote up
void afterBeanDiscovery(@Observes AfterBeanDiscovery abdEvent, BeanManager bm) {
    abdEvent.addBean()
            .types(javax.sql.DataSource.class, DataSource.class)
            .qualifiers(new AnnotationLiteral<Default>() {}, new AnnotationLiteral<Any>() {})
            .scope(ApplicationScoped.class)
            .name(DataSource.class.getName())
            .beanClass(DataSource.class)
            .createWith(creationalContext -> {
                DataSource instance = new DataSource();
                instance.setUrl(dataSourceDefinition.url());
                instance.setDriverClassName(dataSourceDefinition.className());
                return instance;
            });
}
 
Example #23
Source File: UserManagerBean.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID})
@Override
public void removeUserGroups(String pWorkspaceId, String[] pIds) throws UserGroupNotFoundException, AccessRightException, AccountNotFoundException, WorkspaceNotFoundException, EntityConstraintException {
    checkAdmin(pWorkspaceId);
    for (String id : pIds) {
        UserGroupKey userGroupKey = new UserGroupKey(pWorkspaceId, id);
        if (userGroupDAO.hasACLConstraint(userGroupKey)) {
            throw new EntityConstraintException("EntityConstraintException11");
        }
        UserGroup group = userGroupDAO.loadUserGroup(userGroupKey);
        groupEvent.select(new AnnotationLiteral<Removed>() {
        }).fire(new UserGroupEvent(group));
        userGroupDAO.removeUserGroup(group);
    }
}
 
Example #24
Source File: UserManagerBean.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID})
@Override
public void removeUsers(String pWorkspaceId, String[] pLogins) throws UserNotFoundException, AccessRightException, AccountNotFoundException, WorkspaceNotFoundException, EntityConstraintException {
    checkAdmin(pWorkspaceId);
    for (String login : pLogins) {
        User user = userDAO.loadUser(new UserKey(pWorkspaceId, login));
        userEvent.select(new AnnotationLiteral<Removed>() {
        }).fire(new UserEvent(user));
        userDAO.removeUser(user);
    }

}
 
Example #25
Source File: UserManagerBean.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID})
@Override
public Workspace removeUser(String pWorkspaceId, String login) throws UserNotFoundException, AccessRightException, AccountNotFoundException, WorkspaceNotFoundException, EntityConstraintException {
    Account account = accountDAO.loadAccount(contextManager.getCallerPrincipalLogin());
    Workspace workspace = workspaceDAO.loadWorkspace(pWorkspaceId);
    checkAdmin(workspace, account);

    User user = userDAO.loadUser(new UserKey(pWorkspaceId, login));

    userEvent.select(new AnnotationLiteral<Removed>() {
    }).fire(new UserEvent(user));
    userDAO.removeUser(user);

    return workspace;
}
 
Example #26
Source File: WithAnnotationAcceptorTest.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAcceptMethodWithAnnotation() throws Exception {
	WithAnnotationAcceptor acceptor = new WithAnnotationAcceptor();		
	DefaultControllerInstance controllerInstance = new DefaultControllerInstance(new MethodLevelAcceptsController());
	AnnotationLiteral<NotLogged> notLogged = new AnnotationLiteral<NotLogged>() {};
	
	acceptor.initialize(annotation);
	
	when(controllerMethod.getAnnotations()).thenReturn(new Annotation[]{notLogged});
	
	assertTrue(acceptor.validate(controllerMethod, controllerInstance));
}
 
Example #27
Source File: CdiUtilitiesTest.java    From cdi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetReference() {
    Set<Bean<?>> beansFound = beanManager.getBeans(Foo.class,
            new AnnotationLiteral<Default>() {
    });
    assertSame(foo, CdiUtilities.getReference(beanManager,
            beansFound.iterator().next(), Foo.class));
}
 
Example #28
Source File: BeanWrapper.java    From cdi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("serial")
@Override
public Set<Annotation> getQualifiers() {
    final Set<Annotation> qualifiers = new HashSet<>();

    qualifiers.add(new AnnotationLiteral<Default>() {
    });
    qualifiers.add(new AnnotationLiteral<Any>() {
    });

    return qualifiers;
}
 
Example #29
Source File: MongoClientRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private AnnotationLiteral literal(String name) {
    if (name.startsWith(MongoClientBeanUtil.DEFAULT_MONGOCLIENT_NAME)) {
        return Default.Literal.INSTANCE;
    }
    return NamedLiteral.of(name);
}
 
Example #30
Source File: ObserverInheritanceTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("serial")
@BeforeEach
public void setUp() {
    observingBean = Arc.container().instance(ObservingBean.class, new AnnotationLiteral<ObservingBean.THIS>() {
        @Override
        public Class<? extends Annotation> annotationType() {
            return super.annotationType();
        }
    }).get();
    observingSubBean = Arc.container().instance(ObservingSubBean.class).get();
    nonObservingSubBean = Arc.container().instance(NonObservingSubBean.class).get();
    emittingBean = Arc.container().instance(EmittingBean.class).get();
}