if (userRegistered! = null?! userRegistered. equals (users. userRegistered): users. userRegistered! = null) return false;
return displayName! = null? displayName. equals (users. displayName): users. displayName == null;
} @Override public int hashCode () { int result = (int) (id ^ (id >>> 32));= 31 * result + (userLogin! = null? userLogin. hashCode (): 0);= 31 * result + (userPass! = null? userPass. hashCode (): 0);= 31 * result + (userNickname! = null? userNickname. hashCode (): 0);= 31 * result + (userEmail! = null? userEmail. hashCode (): 0);= 31 * result + (groupIdGroup! = null? groupIdGroup. hashCode (): 0);= 31 * result + (userRegistered! = null? userRegistered. hashCode (): 0);= 31 * result + userStatus;= 31 * result + (displayName! = null? displayName. hashCode (): 0);
return result;
} }
Video. java
package wps. newsrussia. entities;
import java. sql. Date;
public class Video { private long id;
private String title;
private Date date;
private String type;
private String description;
private String annotation;
private String path;
private Genre genreId;
private Storage storageId;
/* Getters and setters
…
*/
@Override public boolean equals (Object o) { if (this == o) return true;
if (o == null || getClass ()! = o. getClass ()) return false;video = (Video) o;
if (id! = video. id) return false;
if (title! = null?! title. equals (video. title): video. title! = null) return false;
if (date! = null?! date. equals (video. date): video. date! = null) return false;
if (type! = null?! type. equals (video. type): video. type! = null) return false;
if (description! = null?! description. equals (video. description): video. description! = null) return false;
if (annotation! = null?! annotation. equals (video. annotation): video. annotation! = null) return false;
if (path! = null?! path. equals (video. path): video. path! = null) return false;
if (genreId! = null?! genreId. equals (video. genreId): video. genreId! = null) return false;
return storageId! = null? storageId. equals (video. storageId): video. storageId == null;
} @Override public int hashCode () { int result = (int) (id ^ (id >>> 32));= 31 * result + (title! = null? title. hashCode (): 0);= 31 * result + (date! = null? date. hashCode (): 0);= 31 * result + (type! = null? type. hashCode (): 0);= 31 * result + (description! = null? description. hashCode (): 0);= 31 * result + (annotation! = null? annotation. hashCode (): 0);= 31 * result + (path! = null? path. hashCode (): 0);= 31 * result + (genreId! = null? genreId. hashCode (): 0);= 31 * result + (storageId! = null? storageId. hashCode (): 0);
return result;
} }
Приложение Б. Используемые настройки сущностей
Приложение В. Реализация шаблона DAO
JouranalDAOImpl. java
package wps. newsrussia. dao. impl;
import org. hibernate. Criteria;
import org. hibernate. SessionFactory;
import org. hibernate. criterion. *;
import org. hibernate. transform. Transformers;
import org. springframework. beans. factory. annotation. Autowired;
import org. springframework. stereotype.component;
import org. springframework. transaction. annotation. Transactional;
import wps. newsrussia. entities. Genre;
import wps. newsrussia. dao. interfaces. JournalDAO;
import wps. newsrussia. entities. Journals;
import java. util. Date;
import java. util. List;
@Component public class JournalDAOImpl implements JournalDAO { @Autowired private SessionFactory sessionFactory;
private ProjectionList journalProjection;
public JournalDAOImpl () { journalProjection = Projections. projectionList ();
journalProjection. add (Projections. property ("id"), "id");
journalProjection. add (Projections. property ("genreId"), "genreId");
journalProjection. add (Projections. property ("journalCoversId"), "journalCoversId");
journalProjection. add (Projections. property ("name"), "name");
journalProjection. add (Projections. property ("startDate"), "startDate");
journalProjection. add (Projections. property ("lastmodify"), "lastmodify");
} private DetachedCriteria createJournalCriteria () { DetachedCriteria journalListCriteria = DetachedCriteria. forClass (Journals. class, "b");(journalListCriteria);
return journalListCriteria;
} @Transactional @Override public List<Journals> getJournal () { List<Journals> journals = createJournalList (createJournalCriteria ());
return journals;
} @Transactional @Override public List<Journals> getJournal (String name) { List<Journals> journals = createJournalList (createJournalCriteria (). add (Restrictions. ilike ("b. name",name, MatchMode. ANYWHERE)));
return journals;
} @Transactional @Override public List<Journals> getJournal (Date date_upload) { return null;
} @Transactional @Override public List<Journals> getJournal (Genre genre) { List<Journals> journals = createJournalList (createJournalCriteria (). add (Restrictions. ilike ("genre. name", genre. getName (), MatchMode. ANYWHERE)));
return journals;
} private void createAliases (DetachedCriteria criteria) { criteria. createAlias ("b. genreId", "genreId");. createAlias ("b. storageId", "storageId");
} private List<Journals> createJournalList (DetachedCriteria bookListCriteria) { Criteria criteria = bookListCriteria. getExecutableCriteria (sessionFactory. getCurrentSession ());. addOrder (Order. asc ("b. name")). setProjection (journalProjection). setResultTransformer (Transformers. aliasToBean (Journals. class));
return criteria. list ();
} }
JouranalIssueDAOImpl. java
package wps. newsrussia. dao. impl;
public class JournalIssueDAOImpl implements JournalissueDAO{ @Autowired private SessionFactory sessionFactory;
private DetachedCriteria createJournalCriteria () { DetachedCriteria journalListCriteria = DetachedCriteria. forClass (JournalIssues. class, "b");
return journalListCriteria;
} @Transactional @Override public List<JournalIssues> getJournalIssues () { List<JournalIssues> journalIssues = createJournalList (createJournalCriteria ());
return journalIssues;
} @Transactional @Override public List<JournalIssues> getJournalIssues (int journalsId) { List<JournalIssues> journals = createJournalList (createJournalCriteria (). add (Restrictions. eq ("b. id",journalsId)));
return journals;
} private List<JournalIssues> createJournalList (DetachedCriteria bookListCriteria) { Criteria criteria = bookListCriteria. getExecutableCriteria (sessionFactory. getCurrentSession ());. addOrder (Order. asc ("b. name")). setResultTransformer (Transformers. aliasToBean (JournalIssues. class));
return criteria. list ();
} }
Приложение Г. Вспомогательные классы
NewsrussiaFacade. java
package wps. newsrussia. objects;
@Component @Scope ("singleton") public class NewsrussiaFacade { @Autowired private JournalDAO journalDAO;
@Autowired private SearchCriteria searchCriteria;
private List<Journals> journals;
public List<Journals> getJournals () { if (journals == null) { journals = journalDAO. getJournal ();
} return journals;
} public void searchJournalsByText () { journals = journalDAO. getJournal (searchCriteria. getName ());
} }
SearchCriteria. java
package wps. newsrussia. objects;
import java. io. Serializable;
@Component @Scope ("singleton") public class SearchCriteria implements Serializable { private String name;
private SearchType searchType = SearchType. TEXT;
private String title;
private Genre genre;
public String getName () { return name;
} public void setName (String name) { this. name = name;
} public SearchType getSearchType () { return searchType;
} public void setSearchType (SearchType searchType) { this. searchType = searchType;
} public String getTitle () { return title;
} public void setTitle (String title) { this. title = title;
} public Genre getGenre () { return genre;
} public void setGenre (Genre genre) { this. genre = genre;
} }
Utils. java
package wps. newsrussia. objects;
@Component public class Utils { private Map<String, SearchType> searchTypeList = new HashMap<String, SearchType> ();
private SearchType selectedSearchType = SearchType. TITLE; // значение по-умолчанию @Autowired private MessageSource msg;
private Character [] letters = new Character [] {'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я'};
public Character [] getLetters () { return letters;
} public Map<String, SearchType> getSearchTypeList () { searchTypeList. clear ();
searchTypeList. put (msg. getMessage ("title", null, FacesContext. getCurrentInstance (). getViewRoot (). getLocale ()), SearchType. TITLE);
searchTypeList. put (msg. getMessage ("text", null, FacesContext. getCurrentInstance (). getViewRoot (). getLocale ()), SearchType. TEXT);
return searchTypeList;
} public SearchType getSelectedSearchType () { return selectedSearchType;
} public void setSearchTypeList (Map<String, SearchType> searchTypeList) { this. searchTypeList = searchTypeList;
} public void setSelectedSearchType (SearchType selectedSearchType) { this. selectedSearchType = selectedSearchType;
} }
Приложение Д. Servlets
ShowImage. java
package wps. newsrussia. servlets;
@WebServlet (name = "ShowImage", urlPatterns = {"/ShowImage"}) public class ShowImage extends HttpServlet { // private static Map<Long, Byte [] > imageMap = new HashMap ();
protected void processRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response. setContentType ("image/jpeg");out = response. getOutputStream ();
try { int index = Integer. valueOf (request. getParameter ("index"));newsrussiaFacade = (NewsrussiaFacade) getServletContext (). getAttribute ("newsrussiaFacade");image = newsrussiaFacade. getJournals (). get (index). getJournalCoversId ();fis = new FileInputStream (new File (image. getImg ()));
byte [] img = new byte [fis. available ()];. read (img, 0, fis. available ());. setContentLength (img. length);. write (img);
} catch (Exception ex) { ex. printStackTrace ();
} finally { out. close ();
} } }
PdfContent. java
@WebServlet (name = "PdfContent", urlPatterns = {"/PdfContent"}) public class PdfContent extends HttpServlet { protected void processRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response. setContentType ("application/pdf; charset=UTF-8");out = response. getOutputStream ();
try { long id = Long. valueOf (request. getParameter ("id"));save = Boolean. valueOf (request. getParameter ("save"));libraryFacade = (NewsrussiaFacade) getServletContext (). getAttribute ("libraryFacade");
byte [] content = null; // libraryFacade. getContent (id);
response. setContentLength (content. length);
if (save) { String filename = request. getParameter ("filename");. setHeader ("Content-Disposition", "attachment; filename=" + URLEncoder. encode (filename, "UTF-8") +". pdf");
} out. write (content);
} catch (Exception ex) { ex. printStackTrace ();
} finally { out. close ();
} } }
Приложение Е. Шаблоны JSF
main. xhtml
<? xml version="1.0" encoding="UTF-8"? >
<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Transitional // EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. dtd">
<html xmlns="http://www.w3.org/1999/xhtml": h="http://xmlns. jcp.org/jsf/html": ui="http://xmlns. jcp.org/jsf/facelets": f="http://xmlns. jcp.org/jsf/core": p="http://primefaces.org/ui">
<f: view>
<ui: composition template="/WEB-INF/templates/journals. xhtml">
<ui: define name="title">
#{msg. journal_list}
</ui: define>
<ui: define name="content">
<h: form id="journals_form">
<p: dataGrid rowIndexVar="rowIndex" columns="3" lazy="true" var="b" value="${newsrussiaFacade. journals}" id="journalsList"="list-results list-results-underlined" paginator="true" rows="4" paginatorPosition="bottom"="12,24,80" paginatorTemplate="{RowsPerPageDropdown} {PageLinks}" paginatorAlwaysVisible="true"="">
<div>>
<div>>
<div>>
<h: outputLink styleClass="content_link" value="${flowExecutionUrl}& _eventId=showissues& _index=${rowIndex}">
<p: graphicImage value="/ShowImage? index=#{rowIndex}" width="100%"/>
</h: outputLink>
</div>
<div>>
<div>>
<a href="#"><i>/></a>
</div>
<div>>
<a href="#"><i>/></a>
</div>
<div>>
<a href="#"><i>/></a>
</div>
<div>>
<a href="#"><i>/></a>
</div>
</div>
<div>>
<div>>
<a id="journals_form: journalsList: 0: journalName"="journals_form: journalsList: 0: journalName" href="" target="_blank">>#{b. name}</a>
</div>
<div>>
<p><span>#{msg. genre}: </span>#{b. genreId}</p>
<p><span>#{msg. last_publication}: </span>#{b. lastmodify}</p>
</div>
</div>
</div>
</div>
</p: dataGrid>
</h: form>
</ui: define>
</ui: composition>
</f: view>
</html>
issues. xhtml
<html xmlns="http://www.w3.org/1999/xhtml": h="http://xmlns. jcp.org/jsf/html": ui="http://xmlns. jcp.org/jsf/facelets": f="http://xmlns. jcp.org/jsf/core">
<f: view>
<h: head>
<title><ui: insert name="title"/></title>
<link href='http://fonts. googleapis.com/css? family=Roboto: 300italic,400italic,300,400,500,700,900' rel='stylesheet' type='text/css'/>
</h: head>
<h: body styleClass="menubar-hoverable header-fixed ">
<f: facet name="last">
<! - -<h: outputScript library="js" name="theme-default/bootstrap. css? 1422792965" target="head"/>-->
<h: outputStylesheet library="css" name="theme-default/bootstrap. css" />
<h: outputStylesheet library="css" name="theme-default/materialadmin. css" />
<h: outputStylesheet library="css" name="theme-default/font-awesome. min. css" />
<h: outputStylesheet library="css" name="theme-default/material-design-iconic-font. min. css" />
<h: outputStylesheet library="css" name="theme-default/main. css" />
</f: facet>
<! - HTML5 shim and Respond. js IE8 support of HTML5 elements and media queries - ->
<! - [if lt IE 9] >
<h: outputScript library="js" name="libs/utils/html5shiv. js" target="head"/>
<h: outputScript library="js" name="libs/utils/respond. min. js" target="head"/>
<! [endif] - ->
<header id="header">
<ui: include src="/WEB-INF/templates/header. xhtml"/>
</header>
<div id="base">
<! - BEGIN OFFCANVAS LEFT - ->
<div>>
<! - END OFFCANVAS LEFT - ->
<ui: include src="/WEB-INF/templates/searchTextImg. xhtml">
<ui: param name="issue" value="#{index}"/>
</ui: include>
<ui: include src="/WEB-INF/templates/rightbar. xhtml"/>