[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / service / EPAuditServiceImpl.java
index 1a34386..a7b7161 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.service;\r
-\r
-import java.time.LocalDate;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
-import org.springframework.stereotype.Service;\r
-import org.springframework.transaction.annotation.Transactional;\r
-\r
-import org.openecomp.portalsdk.core.domain.AuditLog;\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.openecomp.portalsdk.core.service.DataAccessService;\r
-import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;\r
-import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;\r
-\r
-@Service("epAuditService")\r
-@Transactional\r
-@org.springframework.context.annotation.Configuration\r
-@EnableAspectJAutoProxy\r
-@EPMetricsLog\r
-public class EPAuditServiceImpl implements EPAuditService {\r
-       EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAuditServiceImpl.class);\r
-\r
-       @Autowired\r
-       private DataAccessService  dataAccessService;\r
-\r
-       @Override\r
-       /* get the guest last login time with orgUserId as param.\r
-        * If record not found in table, return null.\r
-        *  \r
-        * (non-Javadoc)\r
-        * @see org.openecomp.portalapp.portal.service.EPUserService#getGuestLastLogin(java.lang.String)\r
-        */\r
-       public Date getGuestLastLogin(String userId) {\r
-               Map<String, String> params = new HashMap<>();\r
-               params.put("userId", userId);\r
-               List<Date> list = getDataAccessService().executeNamedQuery("getGuestLastLogin", params, null);  \r
-               Date date=null;\r
-               if(list!=null){\r
-                       if(list.size()==1) /* if list only contains one item, meaning this is the first time user logs in or record not found in db*/\r
-                               date = list.get(0); /*the guest's current log in time*/\r
-                       else if(list.size()==2)\r
-                               date = list.get(1); /*most recent login date from db*/\r
-               }\r
-               return date;    \r
-       }\r
-\r
-       @Override\r
-       /* Clean all the records in fn_audit_log table that are less than defined date in system.property\r
-        * \r
-        * (non-Javadoc)\r
-        * @see org.openecomp.portalapp.portal.service.EPAuditService#delAuditLogFromDay()\r
-        */\r
-       public void delAuditLogFromDay(){       \r
-               if (EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM)) {\r
-                       String day = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);                              \r
-                       LocalDate removeDateFrom = LocalDate.now().minusDays(Integer.valueOf(day));\r
-                       getDataAccessService().deleteDomainObjects(AuditLog.class, "audit_date  <'"+removeDateFrom+"'",null);\r
-               }else{\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "delAuditLogFromDay Exception = system.propertiy value is empty on" + EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);\r
-               }       \r
-       }\r
-       \r
-       public DataAccessService getDataAccessService() {\r
-               return dataAccessService;\r
-       }\r
-\r
-       public void setDataAccessService(DataAccessService dataAccessService) {\r
-               this.dataAccessService = dataAccessService;\r
-       }\r
-\r
-\r
-}\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.service;
+
+import java.time.LocalDate;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import org.openecomp.portalsdk.core.domain.AuditLog;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
+import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
+
+@Service("epAuditService")
+@Transactional
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+@EPMetricsLog
+public class EPAuditServiceImpl implements EPAuditService {
+
+       private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAuditServiceImpl.class);
+
+       @Autowired
+       private DataAccessService dataAccessService;
+
+       @Override
+       /*
+        * get the guest last login time with orgUserId as param. If record not
+        * found in table, return null.
+        * 
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.openecomp.portalapp.portal.service.EPUserService#getGuestLastLogin(
+        * java.lang.String)
+        */
+       public Date getGuestLastLogin(String userId) {
+               Map<String, String> params = new HashMap<>();
+               params.put("userId", userId);
+               @SuppressWarnings("unchecked")
+               List<Date> list = getDataAccessService().executeNamedQuery("getGuestLastLogin", params, null);
+               Date date = null;
+               if (list != null) {
+                       /*
+                        * if list only contains one item, meaning this is the first time
+                        * user logs in or record not found in db
+                        */
+                       if (list.size() == 1)
+                               date = list.get(0); /* the guest's current log in time */
+                       else if (list.size() == 2)
+                               date = list.get(1); /* most recent login date from db */
+               }
+               return date;
+       }
+
+       /*
+        * Cleans all the records in fn_audit_log table that are less than defined
+        * date in system.property
+        * 
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.openecomp.portalapp.portal.service.EPAuditService#delAuditLogFromDay(
+        * )
+        */
+       @Override
+       public void delAuditLogFromDay() {
+               if (EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM)) {
+                       String day = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);
+                       LocalDate removeDateFrom = LocalDate.now().minusDays(Integer.valueOf(day));
+                       getDataAccessService().deleteDomainObjects(AuditLog.class, "audit_date  <'" + removeDateFrom + "'", null);
+               } else {
+                       logger.error(EELFLoggerDelegate.errorLogger,
+                                       "delAuditLogFromDay Exception = system.propertiy value is empty on"
+                                                       + EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);
+               }
+       }
+
+       public DataAccessService getDataAccessService() {
+               return dataAccessService;
+       }
+
+       public void setDataAccessService(DataAccessService dataAccessService) {
+               this.dataAccessService = dataAccessService;
+       }
+
+}