org.springframework.messaging.simp.annotation.SendToUser Java Examples

The following examples show how to use org.springframework.messaging.simp.annotation.SendToUser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@MessageMapping("/create/empty")
@SendToUser(broadcast = false)
public int createEmptyPlaylist(Principal p) {
    Locale locale = localeResolver.resolveLocale(p.getName());
    DateTimeFormatter dateFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withLocale(locale);

    Instant now = Instant.now();
    Playlist playlist = new Playlist();
    playlist.setUsername(p.getName());
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    playlist.setName(dateFormat.format(now.atZone(ZoneId.systemDefault())));

    playlistService.createPlaylist(playlist);

    return playlist.getId();
}
 
Example #2
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@MessageMapping("/create/starred")
@SendToUser(broadcast = false)
public int createPlaylistForStarredSongs(Principal p) {
    Locale locale = localeResolver.resolveLocale(p.getName());
    DateTimeFormatter dateFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withLocale(locale);

    Instant now = Instant.now();
    Playlist playlist = new Playlist();
    playlist.setUsername(p.getName());
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);

    ResourceBundle bundle = ResourceBundle.getBundle("org.airsonic.player.i18n.ResourceBundle", locale);
    playlist.setName(bundle.getString("top.starred") + " " + dateFormat.format(now.atZone(ZoneId.systemDefault())));

    playlistService.createPlaylist(playlist);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(p.getName());
    List<MediaFile> songs = mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, p.getName(), musicFolders);
    playlistService.setFilesInPlaylist(playlist.getId(), songs);

    return playlist.getId();
}
 
Example #3
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@MessageMapping("/create/playqueue")
@SendToUser(broadcast = false)
public int createPlaylistForPlayQueue(Principal p, Integer playerId) throws Exception {
    Player player = playerService.getPlayerById(playerId);
    Locale locale = localeResolver.resolveLocale(p.getName());
    DateTimeFormatter dateFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withLocale(locale);

    Instant now = Instant.now();
    Playlist playlist = new Playlist();
    playlist.setUsername(p.getName());
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    playlist.setName(dateFormat.format(now.atZone(ZoneId.systemDefault())));

    playlistService.createPlaylist(playlist);
    playlistService.setFilesInPlaylist(playlist.getId(), player.getPlayQueue().getFiles());

    return playlist.getId();
}
 
Example #4
Source File: SendToMethodReturnValueHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private DestinationHelper getDestinationHelper(MessageHeaders headers, MethodParameter returnType) {
	SendToUser m1 = AnnotatedElementUtils.findMergedAnnotation(returnType.getExecutable(), SendToUser.class);
	SendTo m2 = AnnotatedElementUtils.findMergedAnnotation(returnType.getExecutable(), SendTo.class);
	if ((m1 != null && !ObjectUtils.isEmpty(m1.value())) || (m2 != null && !ObjectUtils.isEmpty(m2.value()))) {
		return new DestinationHelper(headers, m1, m2);
	}

	SendToUser c1 = AnnotatedElementUtils.findMergedAnnotation(returnType.getDeclaringClass(), SendToUser.class);
	SendTo c2 = AnnotatedElementUtils.findMergedAnnotation(returnType.getDeclaringClass(), SendTo.class);
	if ((c1 != null && !ObjectUtils.isEmpty(c1.value())) || (c2 != null && !ObjectUtils.isEmpty(c2.value()))) {
		return new DestinationHelper(headers, c1, c2);
	}

	return (m1 != null || m2 != null ?
			new DestinationHelper(headers, m1, m2) : new DestinationHelper(headers, c1, c2));
}
 
Example #5
Source File: SendToMethodReturnValueHandler.java    From java-technology-stack with MIT License 6 votes vote down vote up
private DestinationHelper getDestinationHelper(MessageHeaders headers, MethodParameter returnType) {
	SendToUser m1 = AnnotatedElementUtils.findMergedAnnotation(returnType.getExecutable(), SendToUser.class);
	SendTo m2 = AnnotatedElementUtils.findMergedAnnotation(returnType.getExecutable(), SendTo.class);
	if ((m1 != null && !ObjectUtils.isEmpty(m1.value())) || (m2 != null && !ObjectUtils.isEmpty(m2.value()))) {
		return new DestinationHelper(headers, m1, m2);
	}

	SendToUser c1 = AnnotatedElementUtils.findMergedAnnotation(returnType.getDeclaringClass(), SendToUser.class);
	SendTo c2 = AnnotatedElementUtils.findMergedAnnotation(returnType.getDeclaringClass(), SendTo.class);
	if ((c1 != null && !ObjectUtils.isEmpty(c1.value())) || (c2 != null && !ObjectUtils.isEmpty(c2.value()))) {
		return new DestinationHelper(headers, c1, c2);
	}

	return (m1 != null || m2 != null ?
			new DestinationHelper(headers, m1, m2) : new DestinationHelper(headers, c1, c2));
}
 
Example #6
Source File: UserSettingsWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/viewAsList")
@SendToUser
public boolean setViewAsList(Principal p, boolean viewAsList) {
    UserSettings userSettings = settingsService.getUserSettings(p.getName());
    if (viewAsList != userSettings.getViewAsList()) {
        userSettings.setViewAsList(viewAsList);
        userSettings.setChanged(Instant.now());
        settingsService.updateUserSettings(userSettings);
    }
    return viewAsList;
}
 
Example #7
Source File: SendToMethodReturnValueHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	if (returnType.getMethodAnnotation(SendTo.class) != null ||
			returnType.getMethodAnnotation(SendToUser.class) != null) {
		return true;
	}
	return (!this.annotationRequired);
}
 
Example #8
Source File: SpittrMessageController.java    From Project with Apache License 2.0 5 votes vote down vote up
@MessageMapping("/spittle")
@SendToUser("/queue/notifications")
public Notification handleSpittle(Principal principal, SpittleForm form) {
	System.out.println("访问spittle");
	Spittle spittle = new Spittle(principal.getName(), form.getText(), new Date());
	spittleRepo.save(spittle);
	feedService.broadcastSpittle(spittle);
	return new Notification("Saved Spittle for user: " + principal.getName());
}
 
Example #9
Source File: SendToMethodReturnValueHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SendTo.class) ||
			AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendTo.class) ||
			returnType.hasMethodAnnotation(SendToUser.class) ||
			AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendToUser.class) ||
			!this.annotationRequired);
}
 
Example #10
Source File: SendToMethodReturnValueHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SendTo.class) ||
			AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendTo.class) ||
			returnType.hasMethodAnnotation(SendToUser.class) ||
			AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendToUser.class) ||
			!this.annotationRequired);
}
 
Example #11
Source File: ArtistWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/info")
@SendToUser(broadcast = false)
public ArtistInfo getArtistInfo(Principal principal, ArtistInfoRequest req) {
    MediaFile mediaFile = mediaFileService.getMediaFile(req.getMediaFileId());
    List<SimilarArtist> similarArtists = getSimilarArtists(principal.getName(), req.getMediaFileId(), req.getMaxSimilarArtists());
    ArtistBio artistBio = lastFmService.getArtistBio(mediaFile, localeResolver.resolveLocale(principal.getName()));
    List<MediaFileEntry> topSongs = getTopSongs(principal.getName(), mediaFile, req.getMaxTopSongs());

    return new ArtistInfo(similarArtists, artistBio, topSongs);
}
 
Example #12
Source File: CoverArtWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Downloads and saves the cover art at the given URL.
 *
 * @return The error string if something goes wrong, <code>"OK"</code> otherwise.
 */
@MessageMapping("/set")
@SendToUser(broadcast = false)
public String setCoverArtImage(CoverArtSetRequest req) {
    try {
        MediaFile mediaFile = mediaFileService.getMediaFile(req.getAlbumId());
        saveCoverArt(mediaFile.getPath(), req.getUrl());
        return "OK";
    } catch (Exception e) {
        LOG.warn("Failed to save cover art for album {}", req.getAlbumId(), e);
        return e.toString();
    }
}
 
Example #13
Source File: UserSettingsWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/sidebar")
@SendToUser
public boolean setShowSideBar(Principal p, boolean show) {
    UserSettings userSettings = settingsService.getUserSettings(p.getName());
    if (show != userSettings.getShowSideBar()) {
        userSettings.setShowSideBar(show);
        userSettings.setChanged(Instant.now());
        settingsService.updateUserSettings(userSettings);
    }
    return show;
}
 
Example #14
Source File: TagWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updated tags for a given music file.
 *
 * @return "UPDATED" if the new tags were updated, "SKIPPED" if no update was necessary.
 *         Otherwise the error message is returned.
 */
@MessageMapping("/edit")
@SendToUser(broadcast = false)
public String setTags(@Validated TagData data) {
    try {
        MediaFile file = mediaFileService.getMediaFile(data.getMediaFileId());
        MetaDataParser parser = metaDataParserFactory.getParser(file.getFile());

        if (!parser.isEditingSupported()) {
            return "Tag editing of " + FilenameUtils.getExtension(file.getPath()) + " files is not supported.";
        }

        if (StringUtils.equals(data.getArtist(), file.getArtist())
                && StringUtils.equals(data.getAlbum(), file.getAlbumName())
                && StringUtils.equals(data.getTitle(), file.getTitle())
                && ObjectUtils.equals(data.getYear(), file.getYear())
                && StringUtils.equals(data.getGenre(), file.getGenre())
                && ObjectUtils.equals(data.getTrack(), file.getTrackNumber())) {
            return "SKIPPED";
        }

        MetaData newMetaData = parser.getMetaData(file.getFile());

        // Note: album artist is intentionally not set, as it is not user-changeable.
        newMetaData.setArtist(data.getArtist());
        newMetaData.setAlbumName(data.getAlbum());
        newMetaData.setTitle(data.getTitle());
        newMetaData.setYear(data.getYear());
        newMetaData.setGenre(data.getGenre());
        newMetaData.setTrackNumber(data.getTrack());
        parser.setMetaData(file, newMetaData);
        mediaFileService.refreshMediaFile(file);
        mediaFileService.refreshMediaFile(mediaFileService.getParentOf(file));
        return "UPDATED";

    } catch (Exception x) {
        LOG.warn("Failed to update tags for " + data.getMediaFileId(), x);
        return x.getMessage();
    }
}
 
Example #15
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/files/rearrange")
@SendToUser(broadcast = false)
public int rearrange(PlaylistFilesModificationRequest req) {
    // in this context, modifierIds are indices
    List<MediaFile> files = playlistService.getFilesInPlaylist(req.getId(), true);
    MediaFile[] newFiles = new MediaFile[files.size()];
    for (int i = 0; i < req.getModifierIds().size(); i++) {
        newFiles[i] = files.get(req.getModifierIds().get(i));
    }
    playlistService.setFilesInPlaylist(req.getId(), Arrays.asList(newFiles));

    return req.getId();
}
 
Example #16
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/files/movedown")
@SendToUser(broadcast = false)
public int down(PlaylistFilesModificationRequest req) {
    // in this context, modifierIds has one element that is the index of the file
    List<MediaFile> files = playlistService.getFilesInPlaylist(req.getId(), true);
    if (req.getModifierIds().size() == 1 && req.getModifierIds().get(0) < files.size() - 1) {
        Collections.swap(files, req.getModifierIds().get(0), req.getModifierIds().get(0) + 1);
        playlistService.setFilesInPlaylist(req.getId(), files);
    }

    return req.getId();
}
 
Example #17
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/files/moveup")
@SendToUser(broadcast = false)
public int up(PlaylistFilesModificationRequest req) {
    // in this context, modifierIds has one element that is the index of the file
    List<MediaFile> files = playlistService.getFilesInPlaylist(req.getId(), true);
    if (req.getModifierIds().size() == 1 && req.getModifierIds().get(0) > 0) {
        Collections.swap(files, req.getModifierIds().get(0), req.getModifierIds().get(0) - 1);
        playlistService.setFilesInPlaylist(req.getId(), files);
    }

    return req.getId();
}
 
Example #18
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/files/remove")
@SendToUser(broadcast = false)
public int remove(PlaylistFilesModificationRequest req) {
    // in this context, modifierIds are indices
    List<MediaFile> files = playlistService.getFilesInPlaylist(req.getId(), true);
    List<Integer> indices = req.getModifierIds();
    Collections.sort(indices);
    for (int i = 0; i < indices.size(); i++) {
        // factor in previous indices we've deleted so far
        files.remove(indices.get(i) - i);
    }
    playlistService.setFilesInPlaylist(req.getId(), files);

    return req.getId();
}
 
Example #19
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@MessageMapping("/files/append")
@SendToUser(broadcast = false)
public int appendToPlaylist(PlaylistFilesModificationRequest req) {
    // in this context, modifierIds are mediafile ids
    List<MediaFile> files = Stream
            .concat(playlistService.getFilesInPlaylist(req.getId(), true).stream(),
                    req.getModifierIds().stream().map(mediaFileService::getMediaFile).filter(Objects::nonNull))
            .collect(Collectors.toList());

    playlistService.setFilesInPlaylist(req.getId(), files);

    return req.getId();
}
 
Example #20
Source File: EventController.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
@MessageMapping("/subscriptions/available")
@SendToUser(broadcast = false)
public Collection<String> listAvailable() {
    return sources.list();
}
 
Example #21
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SendToUser
String handleAndSendToDefaultDest() {
	return PAYLOAD;
}
 
Example #22
Source File: StompWebSocketIntegrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@MessageExceptionHandler
@SendToUser("/queue/error")
public String handleException(IllegalArgumentException ex) {
	return "Got error: " + ex.getMessage();
}
 
Example #23
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SendTo({"/dest1", "/dest2"})
@SendToUser({"/dest1", "/dest2"})
@SuppressWarnings("unused")
String handleAndSendToAndSendToUser() {
	return PAYLOAD;
}
 
Example #24
Source File: SocketController.java    From tutorial with MIT License 4 votes vote down vote up
@MessageMapping("/one")
@SendToUser("/topic/clockmessage")
public ClockMessage toOne(ClockMessage message, Principal principal) throws Exception {
    //由于增加了SendToUser注解,返回结果会被convertAndSend给特定用户,调用这个方法发消息的用户principal中的用户
    return new ClockMessage("toOne, 来自"  + principal.getName() + "的消息:" + message.getMessage() + " ");
}
 
Example #25
Source File: WebSocketController.java    From JavaQuarkBBS with Apache License 2.0 4 votes vote down vote up
@ApiOperation("WebSocket单播:客户端接收一对一消息的主题应该是“/user/” + 用户Id + “/message” ")
@SendToUser("/message")
public SocketMessage sendToUser(SocketMessage message){
    return message;
}
 
Example #26
Source File: SubscriptionMethodReturnValueHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.getMethodAnnotation(SubscribeMapping.class) != null &&
			returnType.getMethodAnnotation(SendTo.class) == null &&
			returnType.getMethodAnnotation(SendToUser.class) == null);
}
 
Example #27
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false)
@SuppressWarnings("unused")
String handleAndSendToUserInSession() {
	return PAYLOAD;
}
 
Example #28
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SendToUser
public String handleAndSendToUserDefaultDestination() {
	return PAYLOAD;
}
 
Example #29
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SendToUser(broadcast = false)
public String handleAndSendToUserDefaultDestinationSingleSession() {
	return PAYLOAD;
}
 
Example #30
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SendToUser({"/dest1", "/dest2"})
public String handleAndSendToUser() {
	return PAYLOAD;
}