Search in sources :

Example 1 with UserProfile

use of org.apereo.portal.UserProfile in project uPortal by Jasig.

the class UserLayoutHelperImpl method resetUserLayoutAllProfiles.

/**
     * Resets a users layout for all the users profiles
     *
     * @param personAttributes
     */
public void resetUserLayoutAllProfiles(final IPersonAttributes personAttributes) {
    RestrictedPerson person = PersonFactory.createRestrictedPerson();
    person.setAttributes(personAttributes.getAttributes());
    // get the integer uid into the person object without creating any new person data
    int uid = userIdentityStore.getPortalUID(person, false);
    person.setID(uid);
    try {
        Hashtable<Integer, UserProfile> userProfileList = userLayoutStore.getUserProfileList(person);
        for (Integer key : userProfileList.keySet()) {
            UserProfile userProfile = userProfileList.get(key);
            userProfile.setLayoutId(0);
            userLayoutStore.updateUserProfile(person, userProfile);
            logger.info("resetUserLayout complete for " + person + "for profile " + userProfile);
        }
    } catch (Exception e) {
        final String msg = "Exception caught during resetUserLayout for " + person;
        logger.error(msg, e);
        throw new PortalException(msg, e);
    }
    return;
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) UserProfile(org.apereo.portal.UserProfile) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 2 with UserProfile

use of org.apereo.portal.UserProfile in project uPortal by Jasig.

the class RDBMUserLayoutStore method addUserProfile.

/**
     * Add a user profile
     *
     * @param person
     * @param profile
     * @return userProfile
     * @exception Exception
     */
public UserProfile addUserProfile(final IPerson person, final IUserProfile profile) {
    final int userId = person.getID();
    final int layoutId = getLayoutId(person, profile);
    return this.jdbcOperations.execute(new ConnectionCallback<UserProfile>() {

        @Override
        public UserProfile doInConnection(Connection con) throws SQLException, DataAccessException {
            String sQuery = null;
            PreparedStatement pstmt = con.prepareStatement("INSERT INTO UP_USER_PROFILE " + "(USER_ID,PROFILE_ID,PROFILE_FNAME,PROFILE_NAME,STRUCTURE_SS_ID,THEME_SS_ID," + "DESCRIPTION, LAYOUT_ID) VALUES (?,?,?,?,?,?,?,?)");
            int profileId = getNextKey();
            pstmt.setInt(1, userId);
            pstmt.setInt(2, profileId);
            pstmt.setString(3, profile.getProfileFname());
            pstmt.setString(4, profile.getProfileName());
            pstmt.setInt(5, profile.getStructureStylesheetId());
            pstmt.setInt(6, profile.getThemeStylesheetId());
            pstmt.setString(7, profile.getProfileDescription());
            pstmt.setInt(8, layoutId);
            sQuery = "INSERT INTO UP_USER_PROFILE (USER_ID,PROFILE_ID,PROFILE_FNAME,PROFILE_NAME,STRUCTURE_SS_ID,THEME_SS_ID,DESCRIPTION, LAYOUT_ID) VALUES (" + userId + ",'" + profileId + ",'" + profile.getProfileFname() + "','" + profile.getProfileName() + "'," + profile.getStructureStylesheetId() + "," + profile.getThemeStylesheetId() + ",'" + profile.getProfileDescription() + "', " + profile.getLayoutId() + ")";
            logger.debug("addUserProfile(): {}", sQuery);
            try {
                pstmt.executeUpdate();
                UserProfile newProfile = new UserProfile();
                newProfile.setProfileId(profileId);
                newProfile.setLayoutId(layoutId);
                newProfile.setLocaleManager(profile.getLocaleManager());
                newProfile.setProfileDescription(profile.getProfileDescription());
                newProfile.setProfileFname(profile.getProfileFname());
                newProfile.setProfileName(profile.getProfileName());
                newProfile.setStructureStylesheetId(profile.getStructureStylesheetId());
                newProfile.setSystemProfile(false);
                newProfile.setThemeStylesheetId(profile.getThemeStylesheetId());
                return newProfile;
            } finally {
                pstmt.close();
            }
        }
    });
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) UserProfile(org.apereo.portal.UserProfile) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IJoinQueryString(org.apereo.portal.jdbc.IJoinQueryString) DataAccessException(org.springframework.dao.DataAccessException)

Example 3 with UserProfile

use of org.apereo.portal.UserProfile in project uPortal by Jasig.

the class RDBMUserLayoutStore method getUserProfileByFname.

public UserProfile getUserProfileByFname(final IPerson person, final String profileFname) {
    Tuple<String, String> key = null;
    final Cache<Tuple<String, String>, UserProfile> profileCache = getProfileImportExportCache();
    if (profileCache != null) {
        key = new Tuple<String, String>(person.getUserName(), profileFname);
        final UserProfile profile = profileCache.getIfPresent(key);
        if (profile != null) {
            return profile;
        }
    }
    logger.debug("Getting profile {} for user {}", profileFname, person.getID());
    final int userId = person.getID();
    final UserProfile userProfile = jdbcOperations.execute(new ConnectionCallback<UserProfile>() {

        @Override
        public UserProfile doInConnection(Connection con) throws SQLException, DataAccessException {
            String query = "SELECT USER_ID, PROFILE_ID, PROFILE_NAME, DESCRIPTION, " + "LAYOUT_ID, STRUCTURE_SS_ID, THEME_SS_ID FROM UP_USER_PROFILE WHERE " + "USER_ID=? AND PROFILE_FNAME=?";
            PreparedStatement pstmt = con.prepareStatement(query);
            pstmt.setInt(1, userId);
            pstmt.setString(2, profileFname);
            try {
                logger.debug("getUserProfileByFname(): {} userId: {} profileFname: {}", query, userId, profileFname);
                ResultSet rs = pstmt.executeQuery();
                try {
                    if (rs.next()) {
                        int profileId = rs.getInt(2);
                        String profileName = rs.getString(3);
                        String profileDesc = rs.getString(4);
                        int layoutId = rs.getInt(5);
                        if (rs.wasNull()) {
                            layoutId = 0;
                        }
                        int structSsId = rs.getInt(6);
                        if (rs.wasNull()) {
                            // This is probably a data issue and probably an export operation;  defer to the system user...
                            if (!person.equals(getSystemUser())) {
                                structSsId = getSystemProfileByFname(profileFname).getStructureStylesheetId();
                            } else {
                                String msg = "The system user profile has no structure stylesheet Id.";
                                throw new IllegalStateException(msg);
                            }
                        }
                        int themeSsId = rs.getInt(7);
                        if (rs.wasNull()) {
                            // This is probably a data issue and probably an export operation;  defer to the system user...
                            if (!person.equals(getSystemUser())) {
                                themeSsId = getSystemProfileByFname(profileFname).getThemeStylesheetId();
                            } else {
                                String msg = "The system user profile has no theme stylesheet Id.";
                                throw new IllegalStateException(msg);
                            }
                        }
                        UserProfile userProfile = new UserProfile(profileId, profileFname, profileName, profileDesc, layoutId, structSsId, themeSsId);
                        final Locale[] userLocales = localeStore.getUserLocales(person);
                        userProfile.setLocaleManager(new LocaleManager(person, userLocales));
                        return userProfile;
                    }
                    /* Try to copy the template profile. */
                    logger.debug("Copying template profile {} to user {}", profileFname, person.getID());
                    rs.close();
                    pstmt.close();
                    pstmt = con.prepareStatement("SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID=?");
                    pstmt.setInt(1, person.getID());
                    rs = pstmt.executeQuery();
                    if (rs.next()) {
                        int defaultProfileUser = rs.getInt(1);
                        if (rs.wasNull()) {
                            throw new RuntimeException("Need to clone the '" + profileFname + "' profile from template user for " + person + " but they have no template user");
                        }
                        IPerson defaultProfilePerson = new PersonImpl();
                        defaultProfilePerson.setID(defaultProfileUser);
                        if (defaultProfilePerson.getID() != person.getID()) {
                            UserProfile templateProfile = getUserProfileByFname(defaultProfilePerson, profileFname);
                            if (templateProfile != null) {
                                UserProfile newUserProfile = new UserProfile(templateProfile);
                                final Locale[] userLocales = localeStore.getUserLocales(person);
                                newUserProfile.setLayoutId(0);
                                newUserProfile = addUserProfile(person, newUserProfile);
                                newUserProfile.setLocaleManager(new LocaleManager(person, userLocales));
                                return newUserProfile;
                            }
                        }
                    }
                    throw new RuntimeException("Unable to find User Profile for userId " + userId + " and profile " + profileFname);
                } finally {
                    rs.close();
                }
            } finally {
                pstmt.close();
            }
        }
    });
    if (profileCache != null && key != null) {
        profileCache.put(key, userProfile);
    }
    return userProfile;
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) UserProfile(org.apereo.portal.UserProfile) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IJoinQueryString(org.apereo.portal.jdbc.IJoinQueryString) IPerson(org.apereo.portal.security.IPerson) PersonImpl(org.apereo.portal.security.provider.PersonImpl) ResultSet(java.sql.ResultSet) LocaleManager(org.apereo.portal.i18n.LocaleManager) Tuple(org.apereo.portal.utils.Tuple) DataAccessException(org.springframework.dao.DataAccessException)

Example 4 with UserProfile

use of org.apereo.portal.UserProfile in project uPortal by Jasig.

the class FragmentActivator method saveLayout.

/**
     * Saves the loaded layout in the database for the user and profile.
     *
     * @param view
     * @param owner
     * @throws Exception
     */
private void saveLayout(UserView view, IPerson owner) throws Exception {
    IUserProfile profile = new UserProfile();
    profile.setProfileId(view.getProfileId());
    userLayoutStore.setUserLayout(owner, profile, view.getLayout(), true, false);
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) UserProfile(org.apereo.portal.UserProfile) IUserProfile(org.apereo.portal.IUserProfile)

Aggregations

IUserProfile (org.apereo.portal.IUserProfile)4 UserProfile (org.apereo.portal.UserProfile)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 IJoinQueryString (org.apereo.portal.jdbc.IJoinQueryString)2 DataAccessException (org.springframework.dao.DataAccessException)2 ResultSet (java.sql.ResultSet)1 PortalException (org.apereo.portal.PortalException)1 LocaleManager (org.apereo.portal.i18n.LocaleManager)1 IPerson (org.apereo.portal.security.IPerson)1 PersonImpl (org.apereo.portal.security.provider.PersonImpl)1 RestrictedPerson (org.apereo.portal.security.provider.RestrictedPerson)1 Tuple (org.apereo.portal.utils.Tuple)1