Search in sources :

Example 31 with Provider

use of javax.inject.Provider in project torodb by torodb.

the class AbstractReadInterface method getCollectionDidsWithFieldsInBatch.

@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
private Cursor<Integer> getCollectionDidsWithFieldsInBatch(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap) throws SQLException {
    @SuppressWarnings("checkstyle:LineLength") Provider<Stream<Map.Entry<MetaField, Collection<KvValue<?>>>>> valuesMultimapSortedStreamProvider = () -> valuesMultimap.asMap().entrySet().stream().sorted((e1, e2) -> e1.getKey().getIdentifier().compareTo(e2.getKey().getIdentifier()));
    String statement = getReadCollectionDidsWithFieldInStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), valuesMultimapSortedStreamProvider.get().map(e -> new Tuple2<String, Integer>(e.getKey().getIdentifier(), e.getValue().size())));
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        int parameterIndex = 1;
        Iterator<Map.Entry<MetaField, Collection<KvValue<?>>>> valuesMultimapSortedIterator = valuesMultimapSortedStreamProvider.get().iterator();
        while (valuesMultimapSortedIterator.hasNext()) {
            Map.Entry<MetaField, Collection<KvValue<?>>> valuesMultimapEntry = valuesMultimapSortedIterator.next();
            for (KvValue<?> value : valuesMultimapEntry.getValue()) {
                sqlHelper.setPreparedStatementValue(preparedStatement, parameterIndex, valuesMultimapEntry.getKey().getType(), value);
                parameterIndex++;
            }
        }
        return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Connection(java.sql.Connection) Provider(javax.inject.Provider) IteratorCursor(com.torodb.core.cursors.IteratorCursor) Multimap(com.google.common.collect.Multimap) Seq(org.jooq.lambda.Seq) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) TableRefFactory(com.torodb.core.TableRefFactory) KvValue(com.torodb.kvdocument.values.KvValue) Tuple2(org.jooq.lambda.tuple.Tuple2) SQLException(java.sql.SQLException) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) ResultSet(java.sql.ResultSet) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Unchecked(org.jooq.lambda.Unchecked) Iterator(java.util.Iterator) Cursor(com.torodb.core.cursors.Cursor) Collection(java.util.Collection) EmptyCursor(com.torodb.core.cursors.EmptyCursor) DocPartTableFields(com.torodb.backend.tables.MetaDocPartTable.DocPartTableFields) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) TableRef(com.torodb.core.TableRef) List(java.util.List) MetaField(com.torodb.core.transaction.metainf.MetaField) Stream(java.util.stream.Stream) DocPartResult(com.torodb.core.d2r.DocPartResult) Entry(java.util.Map.Entry) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaField(com.torodb.core.transaction.metainf.MetaField) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Entry(java.util.Map.Entry) Tuple2(org.jooq.lambda.tuple.Tuple2) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Collection(java.util.Collection) Stream(java.util.stream.Stream) Map(java.util.Map) KvValue(com.torodb.kvdocument.values.KvValue) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 32 with Provider

use of javax.inject.Provider in project OpenAM by OpenRock.

the class RestSTSServiceHttpRouteProvider method get.

@Override
public Set<HttpRoute> get() {
    return Collections.singleton(HttpRoute.newHttpRoute(STARTS_WITH, "rest-sts", new Provider<Handler>() {

        @Override
        public Handler get() {
            Router restSTSRouter = RestSTSInjectorHolder.getInstance(Key.get(Router.class));
            rootRouter.route("").auditAs(STS).authenticateWith(Routers.ssoToken().exceptActions(RestSTSService.TRANSLATE, RestSTSService.VALIDATE, RestSTSService.CANCEL).exceptPatch().exceptRead().exceptUpdate()).toRequestHandler(STARTS_WITH, restSTSRouter);
            return newHttpHandler(rootRouter.getRouter());
        }
    }));
}
Also used : ResourceRouter(org.forgerock.openam.rest.ResourceRouter) Router(org.forgerock.json.resource.Router) Provider(javax.inject.Provider) HttpRouteProvider(org.forgerock.openam.http.HttpRouteProvider)

Example 33 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class UsersAndGroupsMimeMessageFactoryTest method createMessageWhenNotExistingMimeMessageFactory.

@Test
public void createMessageWhenNotExistingMimeMessageFactory() throws Exception {
    Session session = Session.getInstance(new Properties());
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hint", "factoryHint");
    parameters.put("source", "factoryHint");
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    try {
        this.mocker.getComponentUnderTest().createMessage(Collections.<String, Object>emptyMap(), parameters);
        fail("Should have thrown an exception");
    } catch (MessagingException expected) {
        assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) MessagingException(javax.mail.MessagingException) ComponentManager(org.xwiki.component.manager.ComponentManager) Properties(java.util.Properties) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Session(javax.mail.Session) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 34 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class UsersAndGroupsMimeMessageFactoryTest method createMessage.

@Test
public void createMessage() throws Exception {
    DocumentReference userReference = new DocumentReference("userwiki", "userspace", "userpage");
    Map<String, Object> source = Collections.<String, Object>singletonMap("users", Collections.singletonList(userReference));
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hint", "template");
    parameters.put("source", new DocumentReference("templatewiki", "templatespace", "templatepage"));
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    this.mocker.registerMockComponent(new DefaultParameterizedType(null, MimeMessageFactory.class, MimeMessage.class), "template");
    // Setup XWikiContext since this is required internally by the iterator constructor
    Execution execution = this.mocker.registerMockComponent(Execution.class);
    XWikiContext xwikiContext = mock(XWikiContext.class);
    ExecutionContext executionContext = new ExecutionContext();
    executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xwikiContext);
    when(execution.getContext()).thenReturn(executionContext);
    Iterator<MimeMessage> iterator = this.mocker.getComponentUnderTest().createMessage(source, parameters);
    assertNotNull(iterator);
}
Also used : HashMap(java.util.HashMap) XWikiContext(com.xpn.xwiki.XWikiContext) Provider(javax.inject.Provider) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) MimeMessage(javax.mail.internet.MimeMessage) MimeMessageFactory(org.xwiki.mail.MimeMessageFactory) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 35 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class DefaultExtendedRenderingConfigurationTest method configure.

@Before
public void configure() throws Exception {
    Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(contextComponentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Aggregations

Provider (javax.inject.Provider)53 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)23 Test (org.junit.Test)15 ComponentManager (org.xwiki.component.manager.ComponentManager)15 Before (org.junit.Before)11 HashMap (java.util.HashMap)9 File (java.io.File)7 FilesystemExportContext (org.xwiki.url.filesystem.FilesystemExportContext)7 ArrayList (java.util.ArrayList)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 Map (java.util.Map)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Maps (com.google.common.collect.Maps)4 Type (java.lang.reflect.Type)4 Query (org.graylog.plugins.views.search.Query)4 QueryResult (org.graylog.plugins.views.search.QueryResult)4 SearchJob (org.graylog.plugins.views.search.SearchJob)4 SearchType (org.graylog.plugins.views.search.SearchType)4 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4