Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package org.litesoft.GWT.client.context;

import org.litesoft.bo.views.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.core.*;
import org.litesoft.core.util.*;
import org.litesoft.security.*;

import java.util.*;

public abstract class SecurityTypedVoDataProvider<T extends IViewObject> extends TypedVoDataProvider<T> {
    protected SecurityTypedVoDataProvider( VoMetaData<T> pMetaData ) {
        super( pMetaData );
    }

    @Override
    public void commit( TransactionSet pTransactionSet, final CommitCallBack<T> pCallBack, ObjectURL... pReturnOnSuccess ) {
        final SecurityUserView zCurrentUser = checkForCurrentUserInTransaction( pTransactionSet );
        final SecurityRestrictedResourceView zCurrentRestrictedResource = checkForCurrentRestrictedResourceInTransaction( pTransactionSet );
        if ( (zCurrentUser == null) && (zCurrentRestrictedResource == null) ) {
            super.commit( pTransactionSet, pCallBack, pReturnOnSuccess );
            return;
        }
        if ( zCurrentRestrictedResource != null ) {
            pReturnOnSuccess = ObjectURL.prepend( zCurrentRestrictedResource.getObjectURL(), pReturnOnSuccess );
        }
        if ( zCurrentUser != null ) {
            pReturnOnSuccess = ObjectURL.prepend( zCurrentUser.getObjectURL(), pReturnOnSuccess );
        }
        super.commit( pTransactionSet, new CommitCallBack<T>() {
            @Override
            public void success( ImmutableArrayList<T> pRows ) {
                if ( zCurrentUser != null ) {
                    updateContext( (SecurityUserView) pRows.get( 0 ) );
                    pRows = removeFirst( pRows );
                }
                if ( zCurrentRestrictedResource != null ) {
                    updateContext( (SecurityRestrictedResourceView) pRows.get( 0 ) );
                    pRows = removeFirst( pRows );
                }
                pCallBack.success( pRows );
            }

            @Override
            public void error( String pError ) {
                pCallBack.error( pError );
            }
        }, pReturnOnSuccess );
    }

    private ImmutableArrayList<T> removeFirst( ImmutableArrayList<T> pRows ) {
        if ( pRows.isEmpty() ) {
            return pRows;
        }
        ArrayList<T> temp = new ArrayList<T>( pRows );
        temp.remove( 0 );
        return new ImmutableArrayList<T>( temp );
    }

    public static SecurityUserView getCurrentUser() {
        AbstractCurrentUserViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentUserViewAccessor.class );
        return zAccessor != null ? zAccessor.getUser() : null;
    }

    public static SecurityUserView checkForCurrentUserInTransaction( TransactionSet pTransactionSet ) {
        SecurityUserView zCurrentUser = getCurrentUser();
        if ( zCurrentUser != null ) {
            SecurityUserView zTransUser = (SecurityUserView) pTransactionSet.get( zCurrentUser.getObjectURL() );
            if ( zTransUser != null ) {
                return zTransUser;
            }
        }
        return null;
    }

    public static boolean checkForCurrentUser( SecurityUserView pUser ) {
        AbstractCurrentUserViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentUserViewAccessor.class );
        return (zAccessor != null) && Currently.areEqual( pUser, zAccessor.getUser() );
    }

    public static void updateContext( SecurityUserView pUserView ) {
        AbstractCurrentUserViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentUserViewAccessor.class );
        if ( zAccessor != null ) {
            zAccessor.setUser( pUserView );
        }
        if ( pUserView != null ) {
            SecurityRestrictedResourceView zRestrictedResourceView = pUserView.getCurrentRestrictedResource(); // !null on Login!
            if ( zRestrictedResourceView != null ) {
                updateContext( zRestrictedResourceView );
                CurrentRestrictedResourceOptionsAccessor zOptionsAccessor = ClientContext.get().checkGet( CurrentRestrictedResourceOptionsAccessor.class );
                if ( zOptionsAccessor != null ) {
                    zOptionsAccessor.setRestrictedResourceOptions( pUserView.getAlternateRestrictedResourceOptions() );
                }
            }
        }
    }

    public static SecurityRestrictedResourceView checkForCurrentRestrictedResourceInTransaction( TransactionSet pTransactionSet ) {
        AbstractCurrentRestrictedResourceViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentRestrictedResourceViewAccessor.class );
        if ( zAccessor != null ) {
            SecurityRestrictedResourceView zCurrentRestrictedResource = zAccessor.getRestrictedResource();
            if ( zCurrentRestrictedResource != null ) {
                ViewObject zViewObject = pTransactionSet.get( zCurrentRestrictedResource.getObjectURL() );
                return (SecurityRestrictedResourceView) zViewObject;
            }
        }
        return null;
    }

    public static boolean checkForCurrentRestrictedResource( SecurityRestrictedResourceView pRestrictedResource ) {
        AbstractCurrentRestrictedResourceViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentRestrictedResourceViewAccessor.class );
        return (zAccessor != null) && Currently.areEqual( pRestrictedResource, zAccessor.getRestrictedResource() );
    }

    public static void updateContext( SecurityRestrictedResourceView pRestrictedResourceView ) {
        AbstractCurrentRestrictedResourceViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentRestrictedResourceViewAccessor.class );
        if ( zAccessor != null ) {
            zAccessor.setRestrictedResource( pRestrictedResourceView );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/context/SecurityTypedVoDataProvider.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
480 Diff Diff GeorgeS picture GeorgeS Sun 04 Sep, 2011 02:38:20 +0000

Progress on common User Support...

398 GeorgeS picture GeorgeS Mon 15 Aug, 2011 19:57:47 +0000