package fr.openwide.core.basicapp.core.business.audit.service;

import java.util.Date;

import org.apache.http.util.Args;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fr.openwide.core.basicapp.core.business.audit.dao.IAuditDao;
import fr.openwide.core.basicapp.core.business.audit.model.Audit;
import fr.openwide.core.basicapp.core.business.audit.model.atomic.AuditAction;
import fr.openwide.core.basicapp.core.business.user.model.User;
import fr.openwide.core.basicapp.core.business.user.service.IUserService;
import fr.openwide.core.jpa.business.generic.model.GenericEntity;
import fr.openwide.core.jpa.exception.SecurityServiceException;
import fr.openwide.core.jpa.exception.ServiceException;
import fr.openwide.core.jpa.more.business.audit.service.AbstractAuditServiceImpl;

@Service("auditService")
public class AuditServiceImpl extends AbstractAuditServiceImpl<Audit> implements IAuditService {

	@Autowired
	private IUserService userService;

	@Autowired
	public AuditServiceImpl(IAuditDao auditDao) {
		super(auditDao);
	}

	private User getAuthenticatedUser() {
		return userService.getAuthenticatedUser();
	}

	@Override
	public Audit audit(String service, String method, GenericEntity<Long, ?> object,
			AuditAction action) throws ServiceException,
			SecurityServiceException {
		
		return audit(new Date(), service, method, getAuthenticatedUser(), object, action);
	}

	@Override
	public Audit audit(Date date, String service, String method, GenericEntity<Long, ?> object,
			AuditAction action) throws ServiceException,
			SecurityServiceException {
		
		return audit(date, service, method, getAuthenticatedUser(), object, action);
	}

	@Override
	public Audit audit(String service, String method, User subject,
			GenericEntity<Long, ?> object, AuditAction action) throws ServiceException,
			SecurityServiceException {
		
		return audit(new Date(), service, method, null, subject, object, null, action, null);
	}
	
	@Override
	public Audit audit(Date date, String service, String method, User subject,
			GenericEntity<Long, ?> object, AuditAction action) throws ServiceException,
			SecurityServiceException {
		
		return audit(date, service, method, null, subject, object, null, action, null);
	}
	
	@Override
	public Audit audit(Date date, String service, String method, GenericEntity<Long, ?> context, User subject,
			GenericEntity<Long, ?> object, GenericEntity<Long, ?> secondaryObject, AuditAction action,
			String message) throws ServiceException, SecurityServiceException {
		Args.notNull(subject, "subject");
		if (context == null && object == null) {
			throw new IllegalArgumentException("Context and object audit are both null");
		}
		
		Audit audit = new Audit(date, service, method, context, subject, object, secondaryObject,
				action, message);
		
		create(audit);
		return audit;
	}

}

@@ -84,43 +84,35 @@
 te;%0A
-%0A
 import 
-org.apache.http.util.Arg
+java.util.Object
 s;%0A
+%0A
 impo
@@ -2567,16 +2567,26 @@
 %7B%0A%09%09
-Args.not
+Objects.requireNon
 Null
@@ -2603,16 +2603,33 @@
 %22subject
+ must not be null
 %22);%0A%09%09if

Remove a dependency to http client in non related code