Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
feat(glossary export): Rest API for glossary export
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jun 2, 2016
1 parent 62148e1 commit 14fe99e
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 107 deletions.
57 changes: 5 additions & 52 deletions zanata-war/src/main/java/org/zanata/dao/GlossaryDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ private Map<LocaleId, Integer> getLocaleStats(List<Object[]> list) {

@SuppressWarnings("unchecked")
public List<HGlossaryEntry> getEntries() {
Query query = getSession().createQuery("from HGlossaryEntry");
StringBuilder queryString = new StringBuilder();
queryString.append("select term.glossaryEntry from HGlossaryTerm as term ")
.append("where term.locale.localeId = term.glossaryEntry.srcLocale.localeId ")
.append("order by term.content");
Query query = getSession().createQuery(queryString.toString());
query.setComment("GlossaryDAO.getEntries");
return query.list();
}
Expand Down Expand Up @@ -223,16 +227,6 @@ public List<HGlossaryTerm> findByIdList(List<Long> idList) {
return query.list();
}

public String getLastModifiedName(Long termId) {
Query query =
getSession()
.createQuery(
"Select term.lastModifiedBy.name FROM HGlossaryTerm term WHERE term.id =:termId");
query.setLong("termId", termId).setCacheable(true)
.setComment("GlossaryDAO.getLastModifiedName");
return (String) query.uniqueResult();
}

public List<Object[]> getSearchResult(String searchText,
SearchType searchType, LocaleId srcLocale, final int maxResult)
throws ParseException {
Expand Down Expand Up @@ -275,28 +269,6 @@ public List<Object[]> getSearchResult(String searchText,
return matches;
}

public Map<HLocale, Integer> getGlossaryTermCountByLocale() {
Map<HLocale, Integer> result = new HashMap<HLocale, Integer>();

Query query =
getSession()
.createQuery(
"select term.locale, count(*) from HGlossaryTerm term GROUP BY term.locale.localeId");
query.setComment("GlossaryDAO.getGlossaryTermCountByLocale");

@SuppressWarnings("unchecked")
List<Object[]> list = query.list();

for (Object[] obj : list) {
HLocale locale = (HLocale) obj[0];
Long count = (Long) obj[1];
int countInt = count == null ? 0 : count.intValue();
result.put(locale, countInt);
}

return result;
}

public int deleteAllEntries() {
Query query2 = getSession().createQuery("Delete HGlossaryTerm");
query2.setComment("GlossaryDAO.deleteAllEntries-terms");
Expand All @@ -308,23 +280,4 @@ public int deleteAllEntries() {

return rowCount;
}

public int deleteAllEntries(LocaleId targetLocale) {
Query query2 =
getSession()
.createQuery(
"Delete HGlossaryTerm t WHERE t.locale IN (SELECT l FROM HLocale l WHERE localeId= :locale)");
query2.setParameter("locale", targetLocale);
query2.setComment("GlossaryDAO.deleteLocaleEntries-terms");
int rowCount = query2.executeUpdate();

Query query3 =
getSession()
.createQuery(
"Delete HGlossaryEntry e WHERE size(e.glossaryTerms) = 0");
query3.setComment("GlossaryDAO.deleteLocaleEntries-entries");
query3.executeUpdate();

return rowCount;
}
}
Loading

0 comments on commit 14fe99e

Please sign in to comment.