@Provides JavaInputDStream<ConsumerRecord<String, RawRating>> providesKafkaInputStream(JavaStreamingContext streamingContext) { Map<String, Object> kafkaParams = new HashedMap(); kafkaParams.put("bootstrap.servers", "localhost:9092"); kafkaParams.put("key.deserializer", StringDeserializer.class); kafkaParams.put("value.deserializer", JsonDeserializer.class); kafkaParams.put("serializedClass", RawRating.class); kafkaParams.put("group.id", "rating_stream"); kafkaParams.put("auto.offset.reset", "latest"); kafkaParams.put("enable.auto.commit", false); Collection<String> topics = Arrays.asList("topicA", "topicB"); return KafkaUtils.createDirectStream( streamingContext, LocationStrategies.PreferConsistent(), ConsumerStrategies.<String, RawRating>Subscribe(topics, kafkaParams) ); }
@Provides public FeedbackRegistry getFeedbackRegistry() { if (this.feedbackRegistry == null) { FeedbackRegistry registry = mock(FeedbackRegistry.class); List<Feedback> moduleFeedbackList = new FeedbackCreator(GOOD_MP3, WRONG_MP3, ALLOK_MP3).createFeedbackList(); List<Feedback> containerFeedbackList = new FeedbackCreator(CONTAINER_OK_MP3, CONTAINER_WRONG_MP3, CONTAINER_ALL_OK_MP3).createFeedbackList(); when(registry.isModuleRegistered(sender)).thenReturn(true); when(registry.getModuleFeedbacks(sender)).thenReturn(moduleFeedbackList); when(registry.isModuleRegistered(container)).thenReturn(true); when(registry.getModuleFeedbacks(container)).thenReturn(containerFeedbackList); when(registry.hasFeedbacks()).thenReturn(true); this.feedbackRegistry = registry; } return this.feedbackRegistry; }
@Provides @SuppressWarnings("unused") private Function<HubAttributeQueryRequest, Element> getMatchingServiceRequestElementTransformer( IdaKeyStore keyStore, EncryptionKeyStore encryptionKeyStore, EntityToEncryptForLocator entityToEncryptForLocator, SignatureAlgorithm signatureAlgorithm, DigestAlgorithm digestAlgorithm, @Named("HubEntityId") String hubEntityId ) { return hubTransformersFactory.getMatchingServiceRequestToElementTransformer( keyStore, encryptionKeyStore, entityToEncryptForLocator, signatureAlgorithm, digestAlgorithm, hubEntityId ); }
@Provides @Singleton public CertificateStore getCertificateStore(MatchingServiceAdapterConfiguration configuration) { List<Certificate> publicSigningCertificates = configuration.getSigningKeys().stream() .map(KeyPairConfiguration::getPublicKey) .map(key -> cert(key.getName(), key.getCert(), Signing)) .collect(Collectors.toList()); List<Certificate> publicEncryptionCertificates = Stream.of(configuration.getEncryptionKeys().get(0).getPublicKey()) .map(key -> cert(key.getName(), key.getCert(), Encryption)) .collect(Collectors.toList()); return new CertificateStore( publicEncryptionCertificates, publicSigningCertificates); }
@Provides @Singleton protected TraceRecorder traceRecorder() { TracePublisherRESTClient publisher = new TracePublisherRESTClient( PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_USERNAME, "jdoe"), PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_PASSWORD, "password"), PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_URI, "http://localhost:8080") ); BatchTraceRecorder.BatchTraceRecorderBuilder builder = new BatchTraceRecorder.BatchTraceRecorderBuilder(); builder.withTracePublisher(publisher); String batchSize = PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_COLLECTOR_BATCHSIZE); if (batchSize != null) { builder.withBatchSize(Integer.parseInt(batchSize)); } String batchTime = PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_COLLECTOR_BATCHTIME); if (batchTime != null) { builder.withBatchTime(Integer.parseInt(batchTime)); } String threadPoolSize = PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_COLLECTOR_BATCHTHREADS); if (threadPoolSize != null) { builder.withBatchPoolSize(Integer.parseInt(threadPoolSize)); } builder.withTenantId(PropertyUtil.getProperty("HAWKULAR_APM_TENANTID")); return new BatchTraceRecorder(builder); }
@Provides @SuppressWarnings("unused") private Function<MatchingServiceHealthCheckRequest, Element> getMatchingServiceHealthCheckRequestElementTransformer( IdaKeyStore keyStore, EncryptionKeyStore encryptionKeyStore, EntityToEncryptForLocator entityToEncryptForLocator, SignatureAlgorithm signatureAlgorithm, DigestAlgorithm digestAlgorithm, @Named("HubEntityId") String hubEntityId ) { return hubTransformersFactory.getMatchingServiceHealthCheckRequestToElementTransformer( keyStore, encryptionKeyStore, entityToEncryptForLocator, signatureAlgorithm, digestAlgorithm, hubEntityId ); }
@Provides @Singleton public Map<ApiVersion, Function<Build, BuildData>> buildByApiVersion( ) { return ImmutableMap.of( ApiVersion.API_6_0, build -> new BuildData( build.getId( ), build.getStatus( ), build.isRunning( ) ? BuildState.running : BuildState.finished, build.isRunning( ) ? build.getRunningInformation( ).getPercentageComplete( ) : 100, Optional.ofNullable( build.getFinishDate( ) ), build.isRunning( ) ? Duration.of( build.getRunningInformation( ).getEstimatedTotalTime( ) - build.getRunningInformation( ).getElapsedTime( ), ChronoUnit.SECONDS ) : Duration.ZERO ), ApiVersion.API_7_0, build -> new BuildData( build.getId( ), build.getStatus( ), build.isRunning( ) ? BuildState.running : BuildState.finished, build.isRunning( ) ? build.getRunningInformation( ).getPercentageComplete( ) : 100, Optional.ofNullable( build.getFinishDate( ) ), build.isRunning( ) ? Duration.of( build.getRunningInformation( ).getEstimatedTotalTime( ) - build.getRunningInformation( ).getElapsedTime( ), ChronoUnit.SECONDS ) : Duration.ZERO ), ApiVersion.API_8_0, build -> new BuildData( build.getId( ), build.getStatus( ), build.isRunning( ) ? BuildState.running : BuildState.finished, build.isRunning( ) ? build.getRunningInformation( ).getPercentageComplete( ) : 100, Optional.ofNullable( build.getFinishDate( ) ), build.isRunning( ) ? Duration.of( build.getRunningInformation( ).getEstimatedTotalTime( ) - build.getRunningInformation( ).getElapsedTime( ), ChronoUnit.SECONDS ) : Duration.ZERO ), ApiVersion.API_8_1, build -> new BuildData( build.getId( ), build.getStatus( ), build.getState( ), build.getState( ) == BuildState.running ? build.getRunningInformation( ).getPercentageComplete( ) : 100, Optional.ofNullable( build.getFinishDate( ) ), build.getState( ) == BuildState.running ? Duration.of( build.getRunningInformation( ).getEstimatedTotalTime( ) - build.getRunningInformation( ).getElapsedTime( ), ChronoUnit.SECONDS ) : Duration.ZERO ) ); }
@Provides @Singleton @Named("SoapClient") private Client soapClientProvider(Environment environment, SamlSoapProxyConfiguration samlSoapProxyConfiguration) { return new ClientProvider( environment, samlSoapProxyConfiguration.getSoapJerseyClientConfiguration(), samlSoapProxyConfiguration.getEnableRetryTimeOutConnections(), "SoapClient") .get(); }
@Provides @SuppressWarnings("unused") private Function<IdaAuthnRequestFromHub, String> getIdaAuthnRequestFromHubStringTransformer( IdaKeyStore keyStore, SignatureAlgorithm signatureAlgorithm, DigestAlgorithm digestAlgorithm) { return hubTransformersFactory.getIdaAuthnRequestFromHubToStringTransformer( keyStore, signatureAlgorithm, digestAlgorithm ); }
@Provides @Singleton @Named("MatchingServiceClient") public JsonClient getMatchingServiceClient(Environment environment, MatchingServiceAdapterConfiguration configuration) { Client matchingServiceClient = new JerseyClientBuilder(environment).using(configuration.getMatchingServiceClientConfiguration()).build("MatchingServiceClient"); return new JsonClient(new ErrorHandlingClient(matchingServiceClient), new JsonResponseProcessor(environment.getObjectMapper())); }
@Provides CassandraIo<RawRating> providesCassandraRatingIO(JavaSparkContext sparkContext) { if (ratingCassandraIo != null) { return ratingCassandraIo; } ratingCassandraIo = new CassandraIo<>(RawRating.class, "dev", "ratings"); ratingCassandraIo.setSparkContext(sparkContext); return ratingCassandraIo; }
@Provides public FeedbackRegistry getFeedbackRegistry() { if (feedbackRegistry == null) { FeedbackRegistry registry = mock(FeedbackRegistry.class); List<Feedback> feedbackList = new FeedbackCreator(GOOD_MP3, WRONG_MP3, ALLOK_MP3).createFeedbackList(); when(registry.isModuleRegistered(sender)).thenReturn(true); when(registry.getModuleFeedbacks(sender)).thenReturn(feedbackList); this.feedbackRegistry = registry; } return this.feedbackRegistry; }
@Provides public Settings getSettings() { // provider all needed settings for running backend // simulate provided settings if (settings == null || settings.isEmpty()) { settings = new Settings(); settings.put("A", "1"); settings.put("B", "2"); } return settings; }
/** * Generate properties out of the database config. The DatabaseConfig must be provided by a user's configuration. */ @Provides @Jpa public Map<?, ?> properties(final DatabaseConfig cfg) { Properties props = new Properties(); props.setProperty(DRIVER, Driver.class.getName()); props.setProperty(URL, cfg.getUrl()); props.setProperty(USER, cfg.getUser()); props.setProperty(PASS, cfg.getPassword()); props.putAll(cfg.getProperties()); return props; }
@Provides @Named("publisherSaltRedisCache") @Singleton public LoadingCache<Long, String> getLoadingCache( @Named("publisherSaltRedisDao") RedisDao<Long, String> publisherSaltRedisDao, PublisherDao publisherDao) { LoadingCacheRedisImpl<Long, String> l2Cache = new LoadingCacheRedisImpl<>(); l2Cache.setRedisDao(publisherSaltRedisDao); l2Cache.setCacheLoader((key) -> publisherDao.read(key).map((publisher) -> {LOG.debug("found publisher for l3 [{}]", publisher.getSalt());return publisher.getSalt();})); return l2Cache; }
@Provides Predicate<DocLevelEventArg> getInScopePredicate(Parameters params) throws IOException { final Set<Symbol> bannedRoles = params.getSymbolSet("bannedRoles"); // provide files under data/2016.types.txt final Set<Symbol> inScopeEventTypes = FileUtils.loadSymbolMultimap( Files.asCharSource(params.getExistingFile("eventTypesToScore"), Charsets.UTF_8)).keySet(); return and( compose(in(inScopeEventTypes), eventType()), compose(not(in(bannedRoles)), eventArgumentType())); }
@Provides @Singleton public MetricReporter provideMetricReporter(Config config, MetricRegistry metricRegistry) { return config.getMetricsOutputFile() == null ? MetricNullReporter.getInstance() : new MetricFileReporter(config, metricRegistry); }
@Provides @Singleton public MatchingServiceAttributeQueryHandler matchingServiceAttributeQueryHandler( MatchingServiceProxy proxy, InboundMatchingServiceRequestToMatchingServiceRequestDtoMapper inboundMapper, MatchingServiceResponseDtoToOutboundResponseFromMatchingServiceMapper outboundMapper) { return new MatchingServiceAttributeQueryHandler(proxy, inboundMapper, outboundMapper); }
@Provides @Singleton @Named("CountryFixedCertificateChainValidator") public Optional<FixedCertificateChainValidator> getCountryFixedChainCertificateValidator( @Named("CountryTrustStore") Optional<KeyStore> CountryTrustStore, CertificateChainValidator certificateChainValidator) { return CountryTrustStore.map(keyStore -> new FixedCertificateChainValidator(keyStore, certificateChainValidator)); }
@Provides @Singleton @Named(VERIFY_METADATA_HEALTH_CHECK) public MetadataHealthCheck getVerifyMetadataHealthCheck( @Named("VerifyMetadataResolver") MetadataResolver metadataResolver, Environment environment, SamlProxyConfiguration configuration) { MetadataHealthCheck metadataHealthCheck = new MetadataHealthCheck(metadataResolver, configuration.getMetadataConfiguration().getExpectedEntityId()); environment.healthChecks().register(VERIFY_METADATA_HEALTH_CHECK, metadataHealthCheck); return metadataHealthCheck; }
@Provides @Singleton private Function<OutboundResponseFromUnknownUserCreationService, Element> getOutboundResponseFromUnknownUserCreationServiceToElementTransformer( Injector injector ) { return new MsaTransformersFactory().getOutboundResponseFromUnknownUserCreationServiceToElementTransformer( injector.getInstance(EncryptionKeyStore.class), injector.getInstance(IdaKeyStore.class), injector.getInstance(EntityToEncryptForLocator.class), injector.getInstance(MatchingServiceAdapterConfiguration.class) ); }
@Provides @Singleton public JtlPrinter provideJtlPrinter(Config config) throws FileNotFoundException { return config.getJtlOutputFile() == null ? JtlNullPrinter.getInstance() : new JtlFilePrinter(config); }
@Provides @Singleton public static MultiPolygon cuttingPolygon() { try { return (MultiPolygon) new WKTReader().read( "MULTIPOLYGON(((54.34325872314781236 -20.61496515623700532,56.20675565566304499 -20.52773158072990256,56.53804399922131552 -22.11893214296294374,54.34325872314781236 -20.61496515623700532)),((45.76082007284154685 -12.16431241022008969,45.30012222008084422 -13.70552511507818316,44.24672881517291501 -12.87682810499747887,45.76082007284154685 -12.16431241022008969)),((-53.86388748311465946 5.9300516002076753,-51.44935634671445968 4.76504916553769853,-51.70792505978874942 4.19506156747111181,-52.83132503956516501 2.4209224580431643,-54.32717352606223926 2.39156340662024069,-53.83024101072182077 3.6321541115028646,-54.2857624831172032 4.29314308441856074,-54.08647183894422739 5.45617454375176525,-54.04894308127529001 5.52444692910178681,-54.01012022851432448 5.68929854945286895,-53.86388748311465946 5.9300516002076753)),((-61.85375163455503156 14.06546914580407481,-62.18664019134411092 16.64787734392540486,-60.90047985829539812 16.83954045237971897,-60.7491668779367302 15.5735551833788346,-60.83395065310463679 15.58945214122281797,-60.820204658746718 15.48741187449387446,-61.55340163874092241 15.71241305874829131,-61.42503152353879159 15.13474754033868663,-60.68359791978130602 15.20536026450606748,-60.54741623745849921 14.19660706211492318,-61.85375163455503156 14.06546914580407481)),((-63.19163391488151404 18.12705107605973254,-62.95869679831711352 18.16148398444583378,-62.63646712040302589 17.84641758720206184,-63.06351850077108168 17.80329849052715119,-63.19163391488151404 18.12705107605973254)),((130.64811297539733914 42.4089408931416898,130.64862906920575369 42.40916150523329264,130.64976990815063118 42.40597258227973754,130.64922665151021874 42.40577201566927101,130.64811297539733914 42.4089408931416898)),((-179.86638637234364069 64.46187797602119929,-180.00604840193145151 74.87444244885811884,-168.92251888879093258 66.66319302487512743,-170.92273521053905938 63.8183665365200099,-179.86638637234364069 64.46187797602119929)),((-32.23687931365659409 41.00322294346950258,-10.95160324003838959 33.77514040848681987,-12.8151001725536009 28.49700205139115994,-16.29362777991532951 25.80751738504828197,-21.22154189034444727 25.05957208261644098,-34.39025354678528146 39.48611111943009178,-32.23687931365659409 41.00322294346950258)),((-4.29807673062524298 35.17427072899176466,-4.29573216751812215 35.17192616588464205,-4.30101236006188969 35.1696013049885039,-4.30323870990310464 35.1725763388471222,-4.29807673062524298 35.17427072899176466)),((-3.90460387505969742 35.2190341523478665,-3.89898874492919845 35.2184036815963708,-3.89956010904774031 35.21434502613362127,-3.90387489325328163 35.21452234603248144,-3.90460387505969742 35.2190341523478665)),((41.58922823667976587 41.39234273873661607,42.83697397429832421 41.35241003993462527,43.53060894362342736 40.12088814935270165,44.20353839147614394 37.38451555963339246,38.33352305405325922 37.45029534317792042,36.3406166123356158 36.72769605894164613,32.96561661233585738 32.7433656803990587,12.03233440374839525 34.74042051093653782,10.99705833012883183 37.90913363243296885,-1.66436805023835932 36.52413596631321013,-2.42442190500871257 35.16599412262308988,-2.91180021380271947 35.27788708635199555,-2.94306244307358389 35.26923457430100228,-2.96218366565237723 35.2863648108078749,-2.96444245206846135 35.29986105936659158,-2.95684552339777618 35.31583072456704997,-2.93662528758489438 35.3335160029610833,-2.920610860821093 35.52648204242316865,-3.15354797738549308 35.43901922510887914,-5.33377468367367502 35.86489342748320297,-5.34439804822826048 35.87220248338983453,-5.39503017940569762 35.92806746547326213,-5.41019177952885766 35.93163121315374298,-5.41611274517569719 35.91013132850874001,-5.4214949847002698 35.91034769960721462,-5.42793885115186914 35.93580267822458296,-15.32046827071287787 38.26105057334554971,-27.41249281058935239 67.92514246412061141,-13.82967072470070491 68.41785336074353552,-10.35114311733898163 60.15053943510117307,-2.5658670437198734 60.96471012236952447,-0.41249281059118176 67.48527097807296116,-13.66402655292157498 71.21397599847657034,8.366648293702724 81.91103386089542937,107.75315136118064174 82.58107491394852673,179.91167150444769618 75.86878198512971494,179.99698255943999925 51.32875309004389663,146.06987585267864915 43.34780609778923122,145.32756874602708308 43.74354076873730435,145.59446679036946648 44.50845897065210721,138.846833086198302 46.78412166762605295,132.86981588384665542 40.68975414994621076,130.69701627192824844 42.29851249303852256,130.58822555924959374 42.78151351047888085,131.0910692985312096 42.84916937419573912,136.3718321948878156 47.86930878660565725,126.90562534403356665 53.7126410110197483,73.6304519746798718 57.58263070642278336,46.13351945934431342 56.22609091846244667,46.47992836694044172 46.86289373607478836,49.12396580092318032 46.36406504507204573,49.23206133323007094 46.3238956965291635,49.31613264440002098 46.36855210988171905,49.32553191264764081 46.17683382157971295,48.5858590705527007 41.8472293868033276,44.18720044093952737 43.57590255610006125,40.1237070372695328 43.61199216677211865,39.94216467134140913 43.41904389344349369,41.58922823667976587 41.39234273873661607)))"); } catch (ParseException e) { throw propagate(e); } }
@Provides @Singleton private ObjectMapper provideObjectMapper() { return new ObjectMapper(); }
@Provides @Named(SCREEN_NUMBER) public Integer getScreenNumber(ParsedOptions parsedOptions) { return parsedOptions.getScreenNumber(); }
@Provides @InjectorScoped User user(UserId userId, BukkitUserStore userStore) { return userStore.getEverfreshUser(userId); }
@Provides @Named(CONVENTION_EVENT_DETECTOR_PREDICATE) public Predicate<HttpRequest> getConventionEventDetectorPredicate() { return new UriContainsStringPredicate(SUBMIT_EVENT_URL); }
@Provides @EventSink @Singleton public URI eventSinkUri(PolicyConfiguration policyConfiguration) { return policyConfiguration.getEventSinkUri(); }
@Provides @Singleton public EntityManagerFactory createEntityManagerFactory() { Map<String, String> properties = readHerokuDatabaseConnection(); return Persistence.createEntityManagerFactory("bc-grb", properties); }
@Provides @Singleton private Function<EntitiesDescriptor, Element> getEntityDescriptorToElementTransformer() { return new CoreTransformersFactory().getXmlObjectToElementTransformer(); }
@Provides @Named(PATH_TO_DRIVER) public String getPathToDriver(ParsedOptions parsedOptions) { return parsedOptions.getPathToDriver(); }
@Provides ConnectionSurface getConnectionSurface() { return mock(ConnectionSurface.class); }
@Provides @Singleton NativeMethodInvocator getMethodInvocator() { NativeMethodInvocator invocator = mock(NativeMethodInvocator.class); return invocator; }
@Nonnull @Provides @Singleton public PsiFileFactory provideFileFactory(@Nonnull Project project) { return PsiFileFactory.getInstance(project); }
@Provides public FeedbackActionCollector getCollector() { return collector; }
@Provides public FeedbackSoundPlayer getSoundPlayer() { return mock(FeedbackSoundPlayer.class); }
@Provides public MathJaxNative getMathJaxNative() { return mathJaxNative; }
@Provides public ScheduledExecutorService getScheduledExecutorService() { return Executors.newScheduledThreadPool(10, runnable -> new Thread(runnable, EndPointCheckService.class.getName())); }
@Provides @Singleton @Named("SiteClipperConnectorType") protected FileType provideSiteClipperConnectorFile() { return new FileType(GraphicEditorsResources.INSTANCE.icon(), GraphicEditorsExtension.SITECLIPPER_CONNECTOR_EDITOR_EXTENSION); }
@Provides @Singleton public ServiceInfoConfiguration serviceInfo(PolicyConfiguration policyConfiguration) { return policyConfiguration.getServiceInfo(); }