All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.zeger_tak.enversvalidationplugin.execution.SetupExecutor Maven / Gradle / Ivy

Go to download

This is a Maven plugin that allows for easy validation of database auditing with Hibernate and is intended to be used by projects that do not always rely on Envers to create the audit history.

There is a newer version: 0.6
Show newest version
package com.github.zeger_tak.enversvalidationplugin.execution;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Nonnull;

import com.github.zeger_tak.enversvalidationplugin.annotation.TargetPhase;
import com.github.zeger_tak.enversvalidationplugin.annotation.ValidationType;
import com.github.zeger_tak.enversvalidationplugin.connection.ConnectionProviderInstance;
import com.github.zeger_tak.enversvalidationplugin.entities.AuditTableInformation;
import com.github.zeger_tak.enversvalidationplugin.entities.ValidationResults;
import com.github.zeger_tak.enversvalidationplugin.utils.ReflectionUtils;
import org.apache.maven.plugin.logging.Log;
import org.reflections.Reflections;
import org.reflections.scanners.FieldAnnotationsScanner;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ConfigurationBuilder;

public class SetupExecutor extends AbstractExecutor
{
	public SetupExecutor(@Nonnull Log log, @Nonnull List ignorables, @Nonnull ConnectionProviderInstance connectionProvider)
	{
		super(connectionProvider, log, ignorables);
	}

	public void execute(@Nonnull List packagesToScanForValidators, @Nonnull Map providedAuditTableInformationMap, @Nonnull ValidationResults validationResults)
	{
		final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ReflectionUtils.getPackages(packagesToScanForValidators)).setScanners(new SubTypesScanner(), new FieldAnnotationsScanner(), new TypeAnnotationsScanner()));
		final Set> allValidators = reflections.getTypesAnnotatedWith(ValidationType.class);

		final Map>> validatorsGroupedByTargetPhase = groupByTargetPhase(allValidators);
		Map auditTableInformationMap = executeValidators(validatorsGroupedByTargetPhase, TargetPhase.SETUP, providedAuditTableInformationMap, validationResults);
		auditTableInformationMap = executeValidators(validatorsGroupedByTargetPhase, TargetPhase.TABLE_STRUCTURE, auditTableInformationMap, validationResults);
		auditTableInformationMap = executeValidators(validatorsGroupedByTargetPhase, TargetPhase.CONSTRAINTS, auditTableInformationMap, validationResults);
		auditTableInformationMap = executeValidators(validatorsGroupedByTargetPhase, TargetPhase.CONTENT, auditTableInformationMap, validationResults);
	}

	@Nonnull
	private Map>> groupByTargetPhase(@Nonnull Set> allValidators)
	{
		final Map>> validatorsGroupedByTargetPhase = new HashMap<>();
		for (Class validatorClass : allValidators)
		{
			final ValidationType validationType = validatorClass.getAnnotation(ValidationType.class);
			validatorsGroupedByTargetPhase.putIfAbsent(validationType.value(), new HashSet<>());
			validatorsGroupedByTargetPhase.get(validationType.value()).add(validatorClass);
		}
		return validatorsGroupedByTargetPhase;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy