}
public void createListOfKeywords(HashMap<String, Integer> keywords,
User user, Journal journal) throws InstanceNotFoundException,
DuplicateInstanceException {
Keyword keyword;
String key;
int weight;
List<String> s = new ArrayList<String>();
for (String aux : keywords.keySet()) {
s.add(aux);
}
Map<String, Keyword> keywordsMap = keywordDao.findKeywords(s);
Map<Long, KeywordWeight> keywordWeightsMap = keywordWeightJournalDao
.findKeywordWeighJournalsByJournalAndKeyword(journal
.getJournalId());
for (Map.Entry<String, Integer> entry : keywords.entrySet()) {
key = entry.getKey();
key = key.toLowerCase().trim();
try {
keyword = keywordsMap.get(key);
if (keyword == null) {
throw new InstanceNotFoundException("", null);
}
// If the keyword already exists is modified
KeywordWeight kw = keywordWeightsMap
.get(keyword.getKeywordId());
if (kw == null) {
throw new InstanceNotFoundException("", null);
}
if (kw.getUsers().contains(user)) {
if (!user.admin()) {
throw new DuplicateInstanceException(key,
KeywordWeight.class.getName());
}
}
weight = entry.getValue();
weight += kw.getWeight();
kw.setWeight(weight);
kw.addUser(user);
} catch (InstanceNotFoundException e) {
keyword = new Keyword(key);
weight = entry.getValue();
KeywordWeight kw = new KeywordWeight(weight, user, keyword);
KeywordWeightJournal kwj = new KeywordWeightJournal(kw, journal);
createKeywordWeightJournal(kwj);
}