meta = pieceDao.persist(meta);
return meta;
}
public TimelineMusic getUserTimelinePiece(List<Tweet> tweets) {
TimelineMusic meta = new TimelineMusic();
Scale scale = getScale(tweets, meta);
meta.setScale(scale);
Tempo tempo = getTempo(tweets, meta);
meta.setTempo(tempo);
Variation variation = getVariation(tweets, meta);
meta.setVariation(variation);
UserPreferences prefs = new UserPreferences();
prefs.setTempo(tempo);
prefs.setScale(scale);
prefs.setVariation(variation);
List<Piece> pieces = pieceDao.getByPreferences(prefs);
if (pieces.isEmpty()) {
logger.warn("No piece found for preferences " + prefs + ". Getting relaxing criteria");
prefs.setVariation(Variation.ANY);
pieces = pieceDao.getByPreferences(prefs);
if (pieces.isEmpty()) {
prefs.setTempo(Tempo.ANY);
pieces = pieceDao.getByPreferences(prefs);
}
}
Piece piece = pieces.get(random.nextInt(pieces.size()));
meta.setPiece(piece);
return meta;
}