use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class WSResponseTest method illegalControlCharactersAreChomped1.
/*
* Use an authentic response from last.fm, and assert that WSResponse
* silently replaces illegal XML characters in it.
*/
@Test
public void illegalControlCharactersAreChomped1() throws ApplicationException {
String ctrlCharResponse = new ResourceUtil(CTRL_CHAR_RESPONSE_1).getContent();
WSResponse response = new WSResponse(ctrlCharResponse);
// supposed to work, as WSResponse chomps illegal control characters
new ArtistInfoParserImpl(new StringUtil(response.getResponseBody()).getInputStream());
try {
// supposed to fail, as it hasn't passed WSResponse
new ArtistInfoParserImpl(new ResourceUtil(CTRL_CHAR_RESPONSE_1).getInputStream());
Assert.fail();
} catch (ApplicationException e) {
}
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class WSResponseTest method illegalControlCharactersAreChomped2.
/*
* Use an authentic response from last.fm, and assert that WSResponse
* silently replaces illegal XML characters in it.
*/
@Test
public void illegalControlCharactersAreChomped2() throws ApplicationException {
String ctrlCharResponse = new ResourceUtil(CTRL_CHAR_RESPONSE_2).getContent();
WSResponse response = new WSResponse(ctrlCharResponse);
// supposed to work, as WSResponse chomps illegal control characters
new ArtistTopTracksParserImpl(new StringUtil(response.getResponseBody()).getInputStream());
try {
// supposed to fail, as it hasn't passed WSResponse
new ArtistTopTracksParserImpl(new ResourceUtil(CTRL_CHAR_RESPONSE_2).getInputStream());
Assert.fail();
} catch (ApplicationException e) {
}
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class JdbcUserRecommendedArtistsDaoTest method loadFunctionDependency.
@Before
public void loadFunctionDependency() throws ApplicationException {
PostgreSQLUtil.loadFunction(dao, UPDATE_USER_RECOMMENDED_ARTISTS);
joanRec = new UserRecommendedArtists(joan, new UserRecommendedArtistsParserImpl(new ResourceUtil(JOAN_FILE).getInputStream()).getArtists());
rjRec = new UserRecommendedArtists(rj, new UserRecommendedArtistsParserImpl(new ResourceUtil(RJ_FILE).getInputStream()).getArtists());
String body = new WSResponse(new ResourceUtil(FTPAREA_FILE).getContent()).getResponseBody();
ftpareaRec = new UserRecommendedArtists(ftparea, new UserRecommendedArtistsParserImpl(new StringUtil(body).getInputStream()).getArtists());
createArtistMetaData();
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class UserLovedTracksService method updateUserLovedTracks.
private void updateUserLovedTracks() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size());
List<UserLovedTracks> userLovedTracks = new ArrayList<>();
for (LastFmUser user : users) {
short page = 0, totalPages = 0;
List<Track> lovedTracks = new ArrayList<>();
do {
WSResponse wsResponse = userLovedTracksClient.getUserLovedTracks(user, page);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserLovedTracksParser parser = new UserLovedTracksParserImpl(stringUtil.getInputStream());
totalPages = parser.getTotalPages();
lovedTracks.addAll(parser.getLovedTracks());
}
} while (++page < totalPages);
addFinishedOperation();
userLovedTracks.add(new UserLovedTracks(user.getLastFmUsername(), lovedTracks));
}
userLovedTracksDao.createLovedTracks(userLovedTracks);
for (UserStarredTrack ust : userLovedTracksDao.getStarredButNotLovedTracks()) {
trackLoveClient.love(ust.getStarredTrack(), ust.getLastFmUser());
}
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class UserTopArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size() * Period.values().length);
List<UserTopArtists> userTopArtists = new ArrayList<>();
for (LastFmUser user : users) {
for (Period period : Period.values()) {
try {
WSResponse wsResponse = userTopArtistsClient.getUserTopArtists(user, period);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserTopArtistsParser parser = new UserTopArtistsParserImpl(stringUtil.getInputStream());
userTopArtists.add(new UserTopArtists(user, period, parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + user.getLastFmUsername() + ", " + period.getDescription() + " failed.", e);
}
addFinishedOperation();
}
}
userTopArtistsDao.createUserTopArtists(userTopArtists);
}
Aggregations