2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.portal.service;
22 import java.time.LocalDate;
23 import java.util.Date;
24 import java.util.HashMap;
25 import java.util.List;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.context.annotation.EnableAspectJAutoProxy;
30 import org.springframework.stereotype.Service;
31 import org.springframework.transaction.annotation.Transactional;
33 import org.openecomp.portalsdk.core.domain.AuditLog;
34 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
35 import org.openecomp.portalsdk.core.service.DataAccessService;
36 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
37 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
39 @Service("epAuditService")
41 @org.springframework.context.annotation.Configuration
42 @EnableAspectJAutoProxy
44 public class EPAuditServiceImpl implements EPAuditService {
46 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAuditServiceImpl.class);
49 private DataAccessService dataAccessService;
53 * get the guest last login time with orgUserId as param. If record not
54 * found in table, return null.
59 * org.openecomp.portalapp.portal.service.EPUserService#getGuestLastLogin(
62 public Date getGuestLastLogin(String userId) {
63 Map<String, String> params = new HashMap<>();
64 params.put("userId", userId);
65 @SuppressWarnings("unchecked")
66 List<Date> list = getDataAccessService().executeNamedQuery("getGuestLastLogin", params, null);
70 * if list only contains one item, meaning this is the first time
71 * user logs in or record not found in db
74 date = list.get(0); /* the guest's current log in time */
75 else if (list.size() == 2)
76 date = list.get(1); /* most recent login date from db */
82 * Cleans all the records in fn_audit_log table that are less than defined
83 * date in system.property
88 * org.openecomp.portalapp.portal.service.EPAuditService#delAuditLogFromDay(
92 public void delAuditLogFromDay() {
93 if (EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM)) {
94 String day = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);
95 LocalDate removeDateFrom = LocalDate.now().minusDays(Integer.valueOf(day));
96 getDataAccessService().deleteDomainObjects(AuditLog.class, "audit_date <'" + removeDateFrom + "'", null);
98 logger.error(EELFLoggerDelegate.errorLogger,
99 "delAuditLogFromDay Exception = system.propertiy value is empty on"
100 + EPCommonSystemProperties.AUDITLOG_DEL_DAY_FROM);
104 public DataAccessService getDataAccessService() {
105 return dataAccessService;
108 public void setDataAccessService(DataAccessService dataAccessService) {
109 this.dataAccessService = dataAccessService;