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.gringlobal.service.impl;

import java.util.List;

import com.google.common.collect.Lists;
import org.genesys.blocks.auditlog.model.AuditLog;
import org.genesys.blocks.auditlog.model.filters.AuditLogFilter;
import org.genesys.blocks.auditlog.persistence.AuditLogRepository;
import org.gringlobal.custom.elasticsearch.SearchException;
import org.gringlobal.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;


@Service
@Transactional(readOnly = true)
@PreAuthorize("hasAuthority('GROUP_ADMINS')")
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 List<AuditLog> removeAllByFilter(AuditLogFilter filter) {
		Iterable<AuditLog> toDelete = repository.findAll(filter.buildPredicate());
		repository.deleteAll(toDelete);
		return Lists.newArrayList(toDelete);
	}
}