Search in sources :

Example 1 with ArtistUserTag

use of com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag in project musiccabinet by hakko.

the class TagUpdateClientTest method validateParametersForAddingTag.

@Test
public void validateParametersForAddingTag() throws ApplicationException {
    final ArtistUserTag artistUserTagAdd = new ArtistUserTag(artist, lastFmUser, tag, 100, true);
    new TagUpdateClient() {

        @Override
        protected WSResponse executeWSRequest(List<NameValuePair> params) throws ApplicationException {
            assertHasParameter(params, PARAM_METHOD, ADD_METHOD);
            assertHasParameter(params, PARAM_ARTIST, artist.getName());
            assertHasParameter(params, PARAM_TAGS, "pop");
            assertHasParameter(params, PARAM_SK, lastFmUser.getSessionKey());
            return null;
        }
    }.updateTag(artistUserTagAdd);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) Test(org.junit.Test)

Example 2 with ArtistUserTag

use of com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag in project musiccabinet by hakko.

the class TagUpdateClientTest method validateParametersForRemovingTag.

@Test
public void validateParametersForRemovingTag() throws ApplicationException {
    final ArtistUserTag artistUserTagRemove = new ArtistUserTag(artist, lastFmUser, tag, 10, false);
    new TagUpdateClient() {

        @Override
        protected WSResponse executeWSRequest(List<NameValuePair> params) throws ApplicationException {
            assertHasParameter(params, PARAM_METHOD, REMOVE_METHOD);
            assertHasParameter(params, PARAM_ARTIST, artist.getName());
            assertHasParameter(params, PARAM_TAG, "pop");
            assertHasParameter(params, PARAM_SK, lastFmUser.getSessionKey());
            return null;
        }
    }.updateTag(artistUserTagRemove);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) Test(org.junit.Test)

Example 3 with ArtistUserTag

use of com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag in project musiccabinet by hakko.

the class TagUpdateService method updateTags.

protected void updateTags() throws ApplicationException {
    resendFailedUpdates();
    ArtistUserTag aut;
    while (failedUpdates.isEmpty() && (aut = artistUserTags.poll()) != null) {
        if ((aut.isIncrease() && aut.getTagCount() >= MAX_THRESHOLD) || (!aut.isIncrease() && aut.getTagCount() <= MIN_THRESHOLD)) {
            WSResponse wsResponse = tagUpdateClient.updateTag(aut);
            if (!wsResponse.wasCallSuccessful()) {
                LOG.warn("updating " + aut + " failed! Add for re-sending.");
                LOG.debug("Response: " + wsResponse);
                failedUpdates.add(aut);
            }
        }
    }
}
Also used : ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse)

Example 4 with ArtistUserTag

use of com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag in project musiccabinet by hakko.

the class TagUpdateService method resendFailedUpdates.

protected void resendFailedUpdates() throws ApplicationException {
    while (failedUpdates.size() > 0) {
        LOG.debug("Queue of failed updates consists of " + failedUpdates.size() + " elements.");
        ArtistUserTag firstFailed = failedUpdates.get(0);
        WSResponse wsResponse = tagUpdateClient.updateTag(firstFailed);
        if (wsResponse.wasCallSuccessful()) {
            LOG.debug("Failed tag update was re-sent.");
            failedUpdates.remove(0);
        } else {
            LOG.debug("Failed tag update could not be re-sent. Wait a minute before trying again.");
            LOG.debug("Response: " + wsResponse);
            return;
        }
    }
}
Also used : ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse)

Example 5 with ArtistUserTag

use of com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag in project musiccabinet by hakko.

the class TagUpdateService method register.

protected void register(ArtistUserTag submission) {
    for (Iterator<ArtistUserTag> it = artistUserTags.iterator(); it.hasNext(); ) {
        ArtistUserTag aut = it.next();
        if (aut.getArtist().getId() == submission.getArtist().getId() && aut.getTagName().equals(submission.getTagName()) && aut.getLastFmUser().getId() == submission.getLastFmUser().getId()) {
            it.remove();
            LOG.debug("remove " + aut + ", in favor of " + submission);
        }
    }
    artistUserTags.add(submission);
    webserviceHistoryService.blockWebserviceInvocation(submission.getArtist().getId(), ARTIST_GET_TOP_TAGS);
    artistTopTagsDao.updateTopTag(submission.getArtist().getId(), submission.getTagName(), submission.getTagCount());
}
Also used : ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)

Aggregations

ArtistUserTag (com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)6 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)2 NameValuePair (org.apache.http.NameValuePair)2 Test (org.junit.Test)2 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1