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

io.baltoro.service.PermissionResolver Maven / Gradle / Ivy

There is a newer version: 4.0.12
Show newest version
package io.baltoro.service;

import io.baltoro.domain.Permission;
import io.baltoro.exception.CreateNotAllowedException;
import io.baltoro.exception.PermissionException;
import io.baltoro.exception.ReadNotAllowedException;
import io.baltoro.exception.ServiceException;
import io.baltoro.exception.UpdateNotAllowedException;

public class PermissionResolver 
{

	//private static Log log = LogFactory.getLog(PermissionResolver.class);
	
	static void checkReadAllowed(String baseUuid)
	throws PermissionException, ServiceException
	{
		Dao dao = DaoFactory.getInstance();
		Permission p = dao.getPermission(baseUuid);	
		
		if(p instanceof NullPermission)
		{
			throw new PermissionException("no permission records", baseUuid, Ctx.getUserUuid());
		}
		
		if(!p.isRead())
		{
			throw new ReadNotAllowedException(baseUuid, Ctx.getUserUuid());
		}
		
	}
	
	
	static void checkCreateAllowed(String baseUuid)
	throws PermissionException, ServiceException
	{
		Dao dao = DaoFactory.getInstance();
		Permission p = dao.getPermission(baseUuid);	
		
		if(p instanceof NullPermission)
		{
			throw new PermissionException("no permission records", baseUuid, Ctx.getUserUuid());
		}
		
		if(!p.isRead())
		{
			throw new ReadNotAllowedException(baseUuid, Ctx.getUserUuid());
		}
		
		if(!p.isCreate())
		{
			throw new CreateNotAllowedException(baseUuid, Ctx.getUserUuid());
		}
		
	}
	
	static void checkUpdateAllowed(String baseUuid)
	throws PermissionException, ServiceException
	{
		Dao dao = DaoFactory.getInstance();
		Permission p = dao.getPermission(baseUuid);	
		
		if(p instanceof NullPermission)
		{
			throw new ReadNotAllowedException(baseUuid, Ctx.getUserUuid());
		}
		
		if(!p.isRead())
		{
			throw new ReadNotAllowedException(baseUuid, Ctx.getUserUuid());
		}
		
		if(!p.isCreate())
		{
			throw new UpdateNotAllowedException(baseUuid, Ctx.getUserUuid());
		}
		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy