2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.service;
\r
22 import java.time.LocalDate;
\r
23 import java.util.Date;
\r
24 import java.util.HashMap;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
28 import org.springframework.beans.factory.annotation.Autowired;
\r
29 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r
30 import org.springframework.stereotype.Service;
\r
31 import org.springframework.transaction.annotation.Transactional;
\r
33 import org.openecomp.portalsdk.core.domain.AuditLog;
\r
34 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
35 import org.openecomp.portalsdk.core.service.DataAccessService;
\r
36 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
\r
37 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
\r
39 @Service("epAuditService")
\r
41 @org.springframework.context.annotation.Configuration
\r
42 @EnableAspectJAutoProxy
\r
44 public class EPAuditServiceImpl implements EPAuditService {
\r
45 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAuditServiceImpl.class);
\r
48 private DataAccessService dataAccessService;
\r
51 /* get the guest last login time with orgUserId as param.
\r
52 * If record not found in table, return null.
\r
55 * @see org.openecomp.portalapp.portal.service.EPUserService#getGuestLastLogin(java.lang.String)
\r
57 public Date getGuestLastLogin(String userId) {
\r
58 Map<String, String> params = new HashMap<>();
\r
59 params.put("userId", userId);
\r
60 List<Date> list = getDataAccessService().executeNamedQuery("getGuestLastLogin", params, null);
\r
63 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
64 date = list.get(0); /*the guest's current log in time*/
\r
65 else if(list.size()==2)
\r
66 date = list.get(1); /*most recent login date from db*/
\r
72 /* Clean all the records in fn_audit_log table that are less than defined date in system.property
\r
75 * @see org.openecomp.portalapp.portal.service.EPAuditService#delAuditLogFromDay()
\r
77 public void delAuditLogFromDay(){
\r
78 if (EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM)) {
\r
79 String day = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);
\r
80 LocalDate removeDateFrom = LocalDate.now().minusDays(Integer.valueOf(day));
\r
81 getDataAccessService().deleteDomainObjects(AuditLog.class, "audit_date <'"+removeDateFrom+"'",null);
\r
83 logger.error(EELFLoggerDelegate.errorLogger, "delAuditLogFromDay Exception = system.propertiy value is empty on" + EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);
\r
87 public DataAccessService getDataAccessService() {
\r
88 return dataAccessService;
\r
91 public void setDataAccessService(DataAccessService dataAccessService) {
\r
92 this.dataAccessService = dataAccessService;
\r