1
1
package com .fynd .example .java ;
2
2
3
-
4
3
import com .fynd .extension .model .Extension ;
5
4
import com .fynd .extension .model .ExtensionCallback ;
6
5
import com .fynd .extension .model .ExtensionProperties ;
7
6
import com .fynd .extension .session .Session ;
8
- import com .fynd .extension .storage .SQLiteStorage ;
7
+ import com .fynd .extension .storage .MultiLevelStorage ;
9
8
import org .slf4j .Logger ;
10
9
import org .slf4j .LoggerFactory ;
11
10
import org .springframework .beans .factory .annotation .Autowired ;
12
- import org .springframework .beans .factory .annotation .Value ;
13
11
import org .springframework .boot .SpringApplication ;
14
12
import org .springframework .boot .autoconfigure .SpringBootApplication ;
15
13
import org .springframework .context .annotation .Bean ;
16
14
import org .springframework .context .annotation .ComponentScan ;
15
+ import org .springframework .context .annotation .Import ;
16
+ import redis .clients .jedis .JedisPool ;
17
+ import com .mongodb .client .MongoDatabase ;
18
+ import com .fynd .example .java .config .RedisConfig ;
19
+ import com .fynd .example .java .config .MongoConfig ;
20
+
21
+ import java .util .HashMap ;
22
+ import java .util .Map ;
17
23
18
24
@ SpringBootApplication
19
25
@ ComponentScan (basePackages = {"com.fynd.**" ,"com.sdk.**" })
26
+ @ Import ({RedisConfig .class , MongoConfig .class })
20
27
public class ExampleJavaApplication {
21
28
22
- private static final String REDIS_KEY = "ext_sample" ;
29
+ private static final String REDIS_KEY = "ext_sample" ;
23
30
24
- private final Logger logger = LoggerFactory .getLogger (this .getClass ());
31
+ private final Logger logger = LoggerFactory .getLogger (this .getClass ());
25
32
26
- @ Value ( "${sqlite.db.url}" )
27
- private String dbUrl ;
33
+ @ Autowired
34
+ ExtensionProperties extensionProperties ;
28
35
29
- @ Autowired
30
- ExtensionProperties extensionProperties ;
36
+ @ Autowired
37
+ JedisPool jedisPool ;
31
38
39
+ @ Autowired
40
+ MongoDatabase mongoDatabase ;
32
41
33
- ExtensionCallback callbacks = new ExtensionCallback ((request ) -> {
34
- Session fdkSession = (Session ) request .getAttribute ("session" );
35
- logger .debug ("In Auth callback" );
36
- if (request .getParameter ("application_id" ) != null ){
37
- return extensionProperties .getBaseUrl () + "/company/" + fdkSession .getCompanyId () + "/application/" + request .getParameter ("application_id" );
38
- }
39
- else {
40
- return extensionProperties .getBaseUrl () + "/company/" + fdkSession .getCompanyId ();
41
- }
42
- }, (context ) -> {
43
- logger .info ("In install callback" );
44
- return extensionProperties .getBaseUrl ();
42
+ ExtensionCallback callbacks = new ExtensionCallback ((request ) -> {
43
+ Session fdkSession = (Session ) request .getAttribute ("session" );
44
+ logger .debug ("In Auth callback" );
45
+ if (request .getParameter ("application_id" ) != null ){
46
+ return extensionProperties .getBaseUrl () + "/company/" + fdkSession .getCompanyId () + "/application/" + request .getParameter ("application_id" );
47
+ }
48
+ else {
49
+ return extensionProperties .getBaseUrl () + "/company/" + fdkSession .getCompanyId ();
50
+ }
51
+ }, (context ) -> {
52
+ logger .info ("In install callback" );
53
+ return extensionProperties .getBaseUrl ();
45
54
46
- }, (fdkSession ) -> {
47
- logger .info ("In uninstall callback" );
48
- return extensionProperties .getBaseUrl ();
55
+ }, (fdkSession ) -> {
56
+ logger .info ("In uninstall callback" );
57
+ return extensionProperties .getBaseUrl ();
49
58
50
- }, (fdkSession ) -> {
51
- logger .info ("In auto-install callback" );
52
- return extensionProperties .getBaseUrl ();
53
- });
59
+ }, (fdkSession ) -> {
60
+ logger .info ("In auto-install callback" );
61
+ return extensionProperties .getBaseUrl ();
62
+ });
54
63
55
- public static void main (String [] args ) {
56
- SpringApplication .run (ExampleJavaApplication .class , args );
57
- }
64
+ public static void main (String [] args ) {
65
+ SpringApplication .run (ExampleJavaApplication .class , args );
66
+ }
58
67
59
- @ Bean
60
- public com .fynd .extension .model .Extension getExtension () throws ClassNotFoundException {
61
- Extension extension = new Extension ();
62
- return extension .initialize (
63
- extensionProperties ,
64
- new SQLiteStorage (dbUrl , REDIS_KEY ),
65
- callbacks
66
- );
67
- }
68
+ @ Bean
69
+ public com .fynd .extension .model .Extension getExtension () throws ClassNotFoundException {
70
+ Extension extension = new Extension ();
71
+ Map <String , String > options = new HashMap <>();
72
+ // Add any required options to the map
73
+ return extension .initialize (
74
+ extensionProperties ,
75
+ new MultiLevelStorage (jedisPool , mongoDatabase , REDIS_KEY , options ),
76
+ callbacks
77
+ );
78
+ }
68
79
69
80
}
0 commit comments