Search in sources :

Example 51 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class AlbumLocalServiceImpl method moveAlbumToTrash.

@Indexable(type = IndexableType.REINDEX)
@Override
public Album moveAlbumToTrash(long userId, long albumId) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    // Folder
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    Album album = albumPersistence.findByPrimaryKey(albumId);
    int oldStatus = album.getStatus();
    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setStatus(WorkflowConstants.STATUS_IN_TRASH);
    album.setStatusByUserId(user.getUserId());
    album.setStatusByUserName(user.getFullName());
    album.setStatusDate(serviceContext.getModifiedDate(now));
    albumPersistence.update(album);
    // Asset
    assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), false);
    // Trash
    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, album.getGroupId(), Album.class.getName(), album.getAlbumId(), album.getUuid(), null, oldStatus, null, null);
    // Folders and entries
    List<Song> songs = songLocalService.getSongsByAlbumId(album.getAlbumId());
    moveDependentsToTrash(songs, trashEntry.getEntryId());
    return album;
}
Also used : Song(org.liferay.jukebox.model.Song) User(com.liferay.portal.model.User) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) ServiceContext(com.liferay.portal.service.ServiceContext) Album(org.liferay.jukebox.model.Album) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 52 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class AlbumLocalServiceImpl method restoreAlbumFromTrash.

@Indexable(type = IndexableType.REINDEX)
@Override
public Album restoreAlbumFromTrash(long userId, long albumId) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    // Folder
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    Album album = albumPersistence.findByPrimaryKey(albumId);
    TrashEntry trashEntry = trashEntryLocalService.getEntry(Album.class.getName(), albumId);
    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setStatus(trashEntry.getStatus());
    album.setStatusByUserId(user.getUserId());
    album.setStatusByUserName(user.getFullName());
    album.setStatusDate(serviceContext.getModifiedDate(now));
    albumPersistence.update(album);
    assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), true);
    // Songs
    List<Song> songs = songLocalService.getSongsByAlbumId(album.getGroupId(), album.getAlbumId(), WorkflowConstants.STATUS_IN_TRASH);
    restoreDependentsFromTrash(songs, trashEntry.getEntryId());
    // Trash
    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
    return album;
}
Also used : Song(org.liferay.jukebox.model.Song) User(com.liferay.portal.model.User) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) ServiceContext(com.liferay.portal.service.ServiceContext) Album(org.liferay.jukebox.model.Album) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 53 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class AlbumLocalServiceImpl method addAlbum.

@Indexable(type = IndexableType.REINDEX)
public Album addAlbum(long userId, long artistId, String name, int year, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    long groupId = serviceContext.getScopeGroupId();
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    validate(name);
    long albumId = counterLocalService.increment();
    Album album = albumPersistence.create(albumId);
    album.setUuid(serviceContext.getUuid());
    album.setGroupId(groupId);
    album.setCompanyId(user.getCompanyId());
    album.setUserId(user.getUserId());
    album.setUserName(user.getFullName());
    album.setCreateDate(serviceContext.getCreateDate(now));
    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setArtistId(artistId);
    album.setName(name);
    album.setYear(year);
    album.setExpandoBridgeAttributes(serviceContext);
    albumPersistence.update(album);
    if (inputStream != null) {
        PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, Album.class.getName(), album.getAlbumId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(album.getAlbumId()), StringPool.BLANK, true);
    }
    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
        addEntryResources(album, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(album, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }
    // Message boards
    mbMessageLocalService.addDiscussionMessage(userId, album.getUserName(), groupId, Album.class.getName(), albumId, WorkflowConstants.ACTION_PUBLISH);
    // Asset
    updateAsset(userId, album, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return album;
}
Also used : User(com.liferay.portal.model.User) Album(org.liferay.jukebox.model.Album) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 54 with User

use of com.liferay.portal.model.User in project sw360portal by sw360.

the class UserUtils method findLiferayUser.

private static Optional<User> findLiferayUser(PortletRequest request, org.eclipse.sw360.datahandler.thrift.users.User user) {
    long companyId = getCompanyId(request);
    User liferayUser = null;
    try {
        liferayUser = UserLocalServiceUtil.getUserByEmailAddress(companyId, user.getEmail());
    } catch (PortalException | SystemException e) {
        log.error("Could not find Liferay user", e);
    }
    return Optional.ofNullable(liferayUser);
}
Also used : User(com.liferay.portal.model.User) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException)

Example 55 with User

use of com.liferay.portal.model.User in project sw360portal by sw360.

the class TestAutoLogin method login.

@Override
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {
    // first let's check how the incoming request header looks like
    StringBuilder headerRep = new StringBuilder();
    headerRep.append("(login) header from request with URL from client: '" + request.getRequestURL() + "'.\n");
    Enumeration keys = request.getHeaderNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        headerRep.append(" '" + key + "'/'" + request.getHeader(key) + "'\n");
    }
    log.debug("Received header:\n" + headerRep.toString());
    // then, let's login with a hard coded user in any case ...
    long companyId = PortalUtil.getCompanyId(request);
    final String emailId = "user@sw360.org";
    User user = null;
    try {
        user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailId);
    } catch (SystemException e) {
        log.error("System exception at getUserByEmailAddress(): " + e.getMessage(), e);
    } catch (PortalException e) {
        log.error("Portal exception at getUserByEmailAddress(): " + e.getMessage(), e);
    }
    // If user was found by liferay
    if (user != null) {
        // Create a return credentials object
        return new String[] { String.valueOf(user.getUserId()), // Encrypted Liferay password
        user.getPassword(), // True: password is encrypted
        Boolean.TRUE.toString() };
    } else {
        log.error("Could not fetch user from backend: '" + emailId + "'.");
        return new String[] {};
    }
}
Also used : Enumeration(java.util.Enumeration) User(com.liferay.portal.model.User) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException)

Aggregations

User (com.liferay.portal.model.User)97 Date (java.util.Date)22 SystemException (com.liferay.portal.kernel.exception.SystemException)17 Group (com.liferay.portal.model.Group)15 PortalException (com.liferay.portal.kernel.exception.PortalException)13 Company (com.liferay.portal.model.Company)11 ServiceContext (com.liferay.portal.service.ServiceContext)11 Indexable (com.liferay.portal.kernel.search.Indexable)10 UserGroup (com.liferay.portal.model.UserGroup)10 IOException (java.io.IOException)9 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)8 EncryptorException (com.liferay.util.EncryptorException)7 Song (org.liferay.jukebox.model.Song)7 Contact (com.liferay.portal.model.Contact)6 PrincipalException (com.liferay.portal.security.auth.PrincipalException)6 Album (org.liferay.jukebox.model.Album)6 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)5 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)5 NoSuchImageException (com.liferay.portal.NoSuchImageException)5 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)5