[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalsdk / core / lm / FusionLicenseManagerUtils.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalsdk.core.lm;
21
22 import java.util.Date;
23
24 import javax.servlet.ServletContext;
25 import javax.servlet.http.HttpServletRequest;
26
27 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
28 import org.openecomp.portalsdk.core.util.SystemProperties;
29 //import org.openecomp.portalapp.lm.FusionLicenseManagerImpl;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
32 import org.springframework.web.context.WebApplicationContext;
33 import org.springframework.web.servlet.support.RequestContextUtils;
34
35 @Component
36 public class FusionLicenseManagerUtils {
37         
38         @Autowired
39         private FusionLicenseManager licenseManager;
40
41         @Autowired
42         private EPCommonSystemProperties sysProps;
43         static {
44         }
45                 
46         public int verifyLicense(ServletContext context) {
47                 if(sysProps == null) {
48                         try {
49                                 sysProps = new EPCommonSystemProperties();
50                                 sysProps.setServletContext(context);
51 //                              sysProps.load();
52 //                              licenseManager = new FusionLicenseManagerImpl(new LicenseableClassImpl());
53                                 System.out.println(licenseManager);
54                                 licenseManager.installLicense();
55                         }
56                         catch(Exception ex) {
57                                 ex.printStackTrace();
58                         }
59                 }
60                 
61                 
62                 
63 //              WebApplicationContext ctx =RequestContextUtils.getWebApplicationContext(request);
64 //              int flag = ((FusionLicenseManager)ctx.getBean("fusionLicenseManager")).verifyLicense(request);
65 //              logger.debug("****************FLAG ******************** " + flag);
66 //              return flag;
67 //              return 2;
68                 return licenseManager.verifyLicense(context);
69         }
70
71         public static Date getLicenseExpiryDate(HttpServletRequest request) {
72                 WebApplicationContext ctx =RequestContextUtils.getWebApplicationContext(request);
73                 return ((FusionLicenseManager)ctx.getBean("fusionLicenseManager")).getExpiredDate();
74         }
75 }