package com.labs64.netlicensing.gateway.controller.restful;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import com.labs64.netlicensing.domain.vo.Context;
import com.labs64.netlicensing.domain.vo.Page;
import com.labs64.netlicensing.exception.NetLicensingException;
import com.labs64.netlicensing.gateway.controller.restful.exception.MonitoringException;
import com.labs64.netlicensing.gateway.util.Constants;
import com.labs64.netlicensing.service.UtilityService;;

@Path("/" + Constants.Monitoring.ENDPOINT_BASE_PATH)
public class MonitoringController extends AbstractBaseController {

    @GET
    @Path("/")
    public String monitoring() throws NetLicensingException {
        final Context context = getSecurityHelper().getContext();
        final Page<String> licenseTypes = UtilityService.listLicenseTypes(context);
        if (licenseTypes == null) {
            throw new MonitoringException("NetLicensing temporarily unavailable");
        }

        return "Gateway is work";
    }
}
@@ -54,16 +54,44 @@
 stful;%0A%0A
+import javax.inject.Inject;%0A
 import j
@@ -186,55 +186,8 @@
 xt;%0A
-import com.labs64.netlicensing.domain.vo.Page;%0A
 impo
@@ -327,32 +327,121 @@
 oringException;%0A
+import com.labs64.netlicensing.gateway.domain.repositories.MyCommercePurchaseRepository;%0A
 import com.labs6
@@ -657,16 +657,100 @@
 ller %7B%0A%0A
+    @Inject%0A    private MyCommercePurchaseRepository myCommercePurchaseRepository;%0A%0A
     @GET
@@ -827,16 +827,186 @@
 ption %7B%0A
+        checkNetLicensingAvailability();%0A        checkDatabaseAvailability();%0A        return %22Gateway is work%22;%0A    %7D%0A%0A    private void checkNetLicensingAvailability() %7B%0A
         
@@ -1075,41 +1075,25 @@
     
-final Page%3CString%3E licenseTypes =
+try %7B%0A           
  Uti
@@ -1143,32 +1143,46 @@
     
-if (licenseTypes == null
+%7D catch (final NetLicensingException e
 ) %7B%0A
@@ -1278,42 +1278,241 @@
   %7D%0A
-%0A        return %22Gateway is work%22;
+    %7D%0A%0A    private void checkDatabaseAvailability() %7B%0A        try %7B%0A            myCommercePurchaseRepository.count();%0A        %7D catch (final Exception ex) %7B%0A            throw new MonitoringException(%22Database unavailable%22);%0A        %7D
 %0A   

improve monitoring, check database