com.backendless.AbstractDataPermission Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk-common Show documentation
Show all versions of java-sdk-common Show documentation
Provides access to Backendless API
The newest version!
/*
* ********************************************************************************************************************
*
* BACKENDLESS.COM CONFIDENTIAL
*
* ********************************************************************************************************************
*
* Copyright 2012 BACKENDLESS.COM. All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains the property of Backendless.com and its suppliers,
* if any. The intellectual and technical concepts contained herein are proprietary to Backendless.com and its
* suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret
* or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden
* unless prior written permission is obtained from Backendless.com.
*
* ********************************************************************************************************************
*/
package com.backendless;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.core.responder.AdaptingResponder;
import com.backendless.core.responder.policy.PoJoAdaptingPolicy;
import com.backendless.persistence.BackendlessSerializer;
import com.backendless.persistence.PersistenceOperations;
import com.backendless.utils.PermissionTypes;
import java.util.Map;
public abstract class AbstractDataPermission
{
private static final String PERMISSION_SERVICE = "com.backendless.services.persistence.permissions.ClientPermissionService";
protected abstract PersistenceOperations getOperation();
public void grantForUser( String userId, T dataObject )
{
grantForUser( userId, dataObject, null );
}
public void grantForUser( String userId, T dataObject, AsyncCallback responder )
{
String method = "updateUserPermission";
Object[] args = buildArgs( dataObject, userId, PermissionTypes.GRANT );
serverCall( responder, method, args, dataObject.getClass() );
}
public void denyForUser( String userId, T dataObject )
{
denyForUser( userId, dataObject, null );
}
public void denyForUser( String userId, T dataObject, AsyncCallback responder )
{
String method = "updateUserPermission";
Object[] args = buildArgs( dataObject, userId, PermissionTypes.DENY );
serverCall( responder, method, args, null );
}
public void grantForRole( String roleName, T dataObject )
{
grantForRole( roleName, dataObject, null );
}
public void grantForRole( String roleName, T dataObject, AsyncCallback responder )
{
String method = "updateRolePermission";
Object[] args = buildArgs( dataObject, roleName, PermissionTypes.GRANT );
serverCall( responder, method, args, dataObject.getClass() );
}
public void denyForRole( String roleName, T dataObject )
{
denyForRole( roleName, dataObject, null );
}
public void denyForRole( String roleName, T dataObject, AsyncCallback responder )
{
String method = "updateRolePermission";
Object[] args = buildArgs( dataObject, roleName, PermissionTypes.DENY );
serverCall( responder, method, args, null );
}
public void grantForAllUsers( T dataObject )
{
grantForAllUsers( dataObject, null );
}
public void grantForAllUsers( T dataObject, AsyncCallback responder )
{
String method = "updateAllUserPermission";
Object[] args = buildArgs( dataObject, null, PermissionTypes.GRANT );
serverCall( responder, method, args, dataObject.getClass() );
}
public void denyForAllUsers( T dataObject )
{
denyForAllUsers( dataObject, null );
}
public void denyForAllUsers( T dataObject, AsyncCallback responder )
{
String method = "updateAllUserPermission";
Object[] args = buildArgs( dataObject, null, PermissionTypes.DENY);
serverCall( responder, method, args, null );
}
public void grantForAllRoles( T dataObject )
{
grantForAllRoles( dataObject, null );
}
public void grantForAllRoles( T dataObject, AsyncCallback responder )
{
String method = "updateAllRolePermission";
Object[] args = buildArgs( dataObject, null, PermissionTypes.GRANT );
serverCall( responder, method, args, dataObject.getClass() );
}
public void denyForAllRoles( T dataObject )
{
denyForAllRoles( dataObject, null );
}
public void denyForAllRoles( T dataObject, AsyncCallback responder )
{
String method = "updateAllRolePermission";
Object[] args = buildArgs( dataObject, null, PermissionTypes.DENY );
serverCall( responder, method, args, null );
}
private Object[] buildArgs( T dataObject, String principal, PermissionTypes permissionType )
{
final String tableName;
String objectId = Persistence.getEntityId( dataObject );
PersistenceOperations operation = getOperation();
if( dataObject instanceof Map )
tableName = ( String ) ( (Map) dataObject ).get( "___class" );
else
tableName = BackendlessSerializer.getSimpleName( dataObject.getClass() );
if( principal != null )
return new Object[] { tableName, principal, objectId, operation, permissionType };
else
return new Object[] { tableName, objectId, operation, permissionType };
}
private void serverCall( AsyncCallback responder, String method, Object[] args, Class type )
{
if( responder == null )
Invoker.invokeSync( PERMISSION_SERVICE, method, args, new AdaptingResponder<>( type, new PoJoAdaptingPolicy() ) );
else
Invoker.invokeAsync( PERMISSION_SERVICE, method, args, responder, new AdaptingResponder<>( type, new PoJoAdaptingPolicy() ) );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy