AuditLogServiceImpl.java

/*
 * Copyright 2021 Global Crop Diversity Trust
 *
 * 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.genesys.server.service.impl;

import java.time.Instant;

import org.genesys.blocks.auditlog.model.AuditLog;
import org.genesys.blocks.auditlog.model.QAuditLog;
import org.genesys.blocks.auditlog.model.filters.AuditLogFilter;
import org.genesys.blocks.auditlog.persistence.AuditLogRepository;
import org.genesys.server.exception.SearchException;
import org.genesys.server.service.AuditLogService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * The AuditLogServiceImpl class.
 */
@Service
@Transactional(readOnly = true)
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class AuditLogServiceImpl extends FilteredCRUDServiceImpl<AuditLog, AuditLogFilter, AuditLogRepository> implements AuditLogService {

	@Override
	public Page<AuditLog> list(AuditLogFilter filter, Pageable page) throws SearchException {
		return super.list(AuditLog.class, filter, page);
	}

	@Override
	public AuditLog create(AuditLog source) {
		throw new UnsupportedOperationException();
	}

	@Override
	public AuditLog update(AuditLog updated, AuditLog target) {
		throw new UnsupportedOperationException();
	}

	@Override
	@Transactional
	public long removeAllBeforeDate(Instant date) {
		return jpaQueryFactory.delete(QAuditLog.auditLog).where(QAuditLog.auditLog.logDate.before(date)).execute();
	}
}