@@ -25,8 +25,7 @@ public class WorkbenchSetup {
2525
2626 private static final Logger log = Logger .getLogger (WorkbenchSetup .class );
2727
28- private @ Context
29- ServletContext context ;
28+ private @ Context ServletContext context ;
3029
3130 /**
3231 * Get the status of the setup
@@ -36,10 +35,9 @@ public class WorkbenchSetup {
3635 @ GET
3736 @ Produces (MediaType .TEXT_PLAIN )
3837 public Response isSetuUp () {
39- RDFStoreSetupManager setupManager = new RDFStoreSetupManager (
40- context .getInitParameter ("framework-setup-path" ));
41- return Response .ok (setupManager .isSetUp (), MediaType .TEXT_PLAIN )
42- .build ();
38+ RDFStoreSetupManager setupManager = new RDFStoreSetupManager (context
39+ .getInitParameter ("framework-setup-path" ));
40+ return Response .ok (setupManager .isSetUp (), MediaType .TEXT_PLAIN ).build ();
4341 }
4442
4543 /**
@@ -50,26 +48,24 @@ public Response isSetuUp() {
5048 */
5149 @ POST
5250 public Response reset (@ Context ServletContext context ) {
53- RDFStoreSetupManager setupManager = new RDFStoreSetupManager (
54- context .getInitParameter ("framework-setup-path" ));
55- FrameworkConfiguration frameworkConfiguration = null ;
56- try {
57- frameworkConfiguration = FrameworkConfiguration
58- .getInstance (context );
59- setupManager .setUp (frameworkConfiguration , true );
60- } catch (Exception e ) {
61- log .error (e );
62- e .printStackTrace ();
63- if (e .getClass ().getName ()
64- .equals ("virtuoso.jdbc4.VirtuosoException" ))
65- return Response .status (Response .Status .SERVICE_UNAVAILABLE )
66- .entity (e .getMessage ()).build ();
67- else
68- return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
69- .entity (e .getMessage ()).build ();
70- }
71- log .info ("System was reseted successfully." );
72- return Response .ok ().entity ("System reseted successfully" ).build ();
51+ RDFStoreSetupManager setupManager = new RDFStoreSetupManager (context
52+ .getInitParameter ("framework-setup-path" ));
53+ FrameworkConfiguration frameworkConfiguration = null ;
54+ try {
55+ frameworkConfiguration = FrameworkConfiguration .getInstance (context );
56+ setupManager .setUp (frameworkConfiguration , true );
57+ } catch (Exception e ) {
58+ log .error (e );
59+ e .printStackTrace ();
60+ if (e .getClass ().getName ().equals ("virtuoso.jdbc4.VirtuosoException" ))
61+ return Response .status (Response .Status .SERVICE_UNAVAILABLE ).entity (e .getMessage ())
62+ .build ();
63+ else
64+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
65+ .entity (e .getMessage ()).build ();
66+ }
67+ log .info ("System was reseted successfully." );
68+ return Response .ok ().entity ("System reseted successfully" ).build ();
7369 }
7470
7571 /**
@@ -80,35 +76,33 @@ public Response reset(@Context ServletContext context) {
8076 */
8177 @ PUT
8278 public Response initialize (@ Context ServletContext context ) {
83- RDFStoreSetupManager setupManager = new RDFStoreSetupManager (
84- context .getInitParameter ("framework-setup-path" ));
79+ RDFStoreSetupManager setupManager = new RDFStoreSetupManager (context
80+ .getInitParameter ("framework-setup-path" ));
81+
82+ if (setupManager .isSetUp ()) {
83+ log .info ("System is already set up. To reset system use PUT method" );
84+ return Response .status (Response .Status .CONFLICT ).entity (
85+ "System is already set up. To reset system use PUT method" ).build ();
86+ } else {
87+ FrameworkConfiguration frameworkConfiguration = null ;
88+ try {
89+ frameworkConfiguration = FrameworkConfiguration .getInstance (context );
90+ } catch (Exception e ) {
91+ log .error (e );
92+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
93+ .entity (e .getMessage ()).build ();
94+ }
95+ try {
96+ setupManager .setUp (frameworkConfiguration , false );
97+ } catch (Exception e ) {
98+ log .error (e );
99+ e .printStackTrace ();
100+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
101+ .entity (e .getMessage ()).build ();
102+ }
103+ log .info ("System was set up successfully." );
104+ return Response .ok ().entity ("System initialized successfully" ).build ();
105+ }
85106
86- if (setupManager .isSetUp ()) {
87- log .info ("System is already set up. To reset system use PUT method" );
88- return Response
89- .status (Response .Status .CONFLICT )
90- .entity ("System is already set up. To reset system use PUT method" )
91- .build ();
92- } else {
93- FrameworkConfiguration frameworkConfiguration = null ;
94- try {
95- frameworkConfiguration = FrameworkConfiguration
96- .getInstance (context );
97- } catch (Exception e ) {
98- log .error (e );
99- return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
100- .entity (e .getMessage ()).build ();
101- }
102- try {
103- setupManager .setUp (frameworkConfiguration , false );
104- } catch (Exception e ) {
105- log .error (e );
106- return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
107- .entity (e .getMessage ()).build ();
108- }
109- log .info ("System was set up successfully." );
110- return Response .ok ().entity ("System initialized successfully" )
111- .build ();
112- }
113107 }
114108}
0 commit comments