Search in sources :

Example 1 with UnicodeProperties

use of com.liferay.portal.kernel.util.UnicodeProperties in project liferay-ide by liferay.

the class SongLocalServiceImpl method moveSongToTrash.

@Indexable(type = IndexableType.REINDEX)
public Song moveSongToTrash(long userId, Song song) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    // Entry
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    int oldStatus = song.getStatus();
    song.setModifiedDate(serviceContext.getModifiedDate(now));
    song.setStatus(WorkflowConstants.STATUS_IN_TRASH);
    song.setStatusByUserId(user.getUserId());
    song.setStatusByUserName(user.getFullName());
    song.setStatusDate(serviceContext.getModifiedDate(now));
    // Asset
    assetEntryLocalService.updateVisible(Song.class.getName(), song.getSongId(), false);
    // Trash
    UnicodeProperties typeSettingsProperties = new UnicodeProperties();
    typeSettingsProperties.put("title", song.getName());
    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, song.getGroupId(), Song.class.getName(), song.getSongId(), song.getUuid(), null, oldStatus, null, typeSettingsProperties);
    song.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId()));
    songPersistence.update(song);
    return song;
}
Also used : Song(org.liferay.jukebox.model.Song) User(com.liferay.portal.model.User) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) ServiceContext(com.liferay.portal.service.ServiceContext) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 2 with UnicodeProperties

use of com.liferay.portal.kernel.util.UnicodeProperties in project liferay-ide by liferay.

the class UserLocalServiceImpl method addDefaultRolesAndTeams.

protected void addDefaultRolesAndTeams(long groupId, long[] userIds) throws PortalException, SystemException {
    List<Role> defaultSiteRoles = new ArrayList<Role>();
    Group group = groupLocalService.getGroup(groupId);
    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();
    long[] defaultSiteRoleIds = StringUtil.split(typeSettingsProperties.getProperty("defaultSiteRoleIds"), 0L);
    for (long defaultSiteRoleId : defaultSiteRoleIds) {
        Role defaultSiteRole = rolePersistence.fetchByPrimaryKey(defaultSiteRoleId);
        if (defaultSiteRole == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find role " + defaultSiteRoleId);
            }
            continue;
        }
        defaultSiteRoles.add(defaultSiteRole);
    }
    List<Team> defaultTeams = new ArrayList<Team>();
    long[] defaultTeamIds = StringUtil.split(typeSettingsProperties.getProperty("defaultTeamIds"), 0L);
    for (long defaultTeamId : defaultTeamIds) {
        Team defaultTeam = teamPersistence.findByPrimaryKey(defaultTeamId);
        if (defaultTeam == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find team " + defaultTeamId);
            }
            continue;
        }
        defaultTeams.add(defaultTeam);
    }
    for (long userId : userIds) {
        Set<Long> userRoleIdsSet = new HashSet<Long>();
        for (Role role : defaultSiteRoles) {
            if (!userPersistence.containsRole(userId, role.getRoleId())) {
                userRoleIdsSet.add(role.getRoleId());
            }
        }
        long[] userRoleIds = ArrayUtil.toArray(userRoleIdsSet.toArray(new Long[userRoleIdsSet.size()]));
        userGroupRoleLocalService.addUserGroupRoles(userId, groupId, userRoleIds);
        Set<Long> userTeamIdsSet = new HashSet<Long>();
        for (Team team : defaultTeams) {
            if (!userPersistence.containsTeam(userId, team.getTeamId())) {
                userTeamIdsSet.add(team.getTeamId());
            }
        }
        long[] userTeamIds = ArrayUtil.toArray(userTeamIdsSet.toArray(new Long[userTeamIdsSet.size()]));
        userPersistence.addTeams(userId, userTeamIds);
    }
}
Also used : Role(com.liferay.portal.model.Role) UserGroupRole(com.liferay.portal.model.UserGroupRole) Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) ArrayList(java.util.ArrayList) Team(com.liferay.portal.model.Team) HashSet(java.util.HashSet)

Aggregations

UnicodeProperties (com.liferay.portal.kernel.util.UnicodeProperties)2 Indexable (com.liferay.portal.kernel.search.Indexable)1 Group (com.liferay.portal.model.Group)1 Role (com.liferay.portal.model.Role)1 Team (com.liferay.portal.model.Team)1 User (com.liferay.portal.model.User)1 UserGroup (com.liferay.portal.model.UserGroup)1 UserGroupRole (com.liferay.portal.model.UserGroupRole)1 ServiceContext (com.liferay.portal.service.ServiceContext)1 TrashEntry (com.liferay.portlet.trash.model.TrashEntry)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Song (org.liferay.jukebox.model.Song)1