review until page 10

This commit is contained in:
Daniel Sommer 2019-03-02 13:06:48 +01:00
parent 1603346644
commit 7ac2c8ae24
1 changed files with 39 additions and 126 deletions

View File

@ -97,10 +97,9 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
\end{itemize}
\section{Service Layer Pattern (auch Session Fassade)}\label{sec:slp}
\subsection{Erkläre die Funktion + Skizze}\label{subsubsec:service-layer-pattern}
\begin{itemize}
\item Service Layer delegiert auf Business Logik (z.B.: Zeile 82 community.setDocumentlibrary) und zum DAO (z.B.: Zeile 80, 81,82 ...)
\item bei wenig Logik wird zumindest Transaktions (z.B. Zeile 39), Error (z.B. Zeile 42-50) und Validierungshandling (z.B.: Zeile 24-27) im Service erledigt
\item Der Service Layer delegiert auf die Business Logik (Zeile 68 community.setDocumentlibrary) und zum DAO (z.B. Zeile 66)
\item Bei wenig Logik wird zumindest Transaktions (Zeile 40), Error (ab Zeile 42) und Validierungshandling (ab Zeile 23) im Service erledigt
\end{itemize}
\begin{minted}[xleftmargin=\parindent,linenos,breaklines=true]{java}
@Local(DocumentService.class)
@ -125,6 +124,7 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
Document addedDocument;
User user;
// Validierungshandling gefolgt von Error Handling
try {
if (communityID <= 0) throw new IllegalArgumentException("community must not be empty");
if (userID == null) throw new IllegalArgumentException("user must not be empty");
@ -141,9 +141,9 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
user = userDAO.getByUserId(userID);
addedDocument = new Document(documentlibrary, user, filename, data);
documentDAO.insert(addedDocument);
documentDAO.insert(addedDocument); // Transaktionshandling
logger.info(String.format("Document %s saved in database", filename));
// Error Handling
} catch (IllegalArgumentException iaex) {
String errorMsg = "Uploading file failed (illegal argument)";
logger.error(errorMsg, iaex);
@ -161,130 +161,35 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
}
private void addMessageToStream(Long communityID, User user, String text, Document document) {
try {
Activitystream activitystream = communityDAO.findById(communityID).getActivitystream();
Date now = new Date();
Calendar calendar = Calendar.getInstance();
calendar.set(9999, Calendar.DECEMBER, 31);
Date until = calendar.getTime();
Message message = new Message(user, text, now, until, now, activitystream, null, "Document Upload", null, null);
messageDAO.insert(message);
} catch (Exception ex) {
String errorMsg = String.format("Add entry to stream for %s failed.", document.getFilename());
logger.error(errorMsg, ex);
throw new ServiceException(errorMsg);
}
}
private void addMessageToStream(Long communityID, User user, String text, Document document) {...}
private Documentlibrary addDocumentlibrary(Long communityID) {
logger.info("Create missing documentlibrary");
Community community;
Documentlibrary documentlibrary = new Documentlibrary();
documentlibraryDAO.insert(documentlibrary);
community = communityDAO.findById(communityID);
community.setDocumentlibrary(documentlibrary);
communityDAO.update(community);
documentlibraryDAO.insert(documentlibrary); // Delegation zum DAO
community = communityDAO.findById(communityID); // Delegation zum DAO
community.setDocumentlibrary(documentlibrary); // Delegation zur Business Logik (Entity)
communityDAO.update(community); // Delegation zum DAO
return documentlibrary;
}
@Override
public List<DocumentDTO> getDocumentsFromCommunity(Long communityID) {...}
@Override
public List<DocumentDTO> getDocumentsFromCommunity(Long communityID) {
try {
List<Document> documents;
if (communityID <= 0) throw new IllegalArgumentException("community must not be empty");
Community community = communityDAO.findById(communityID);
if (community == null) throw new IllegalStateException("community " + communityID + " not found");
documents = documentDAO.findByCommunity(community);
return documents.stream().map(DocumentMapper::toDTO).collect(Collectors.toList());
} catch (IllegalArgumentException iaex) {
String errorMsg = "Could not load docs from community (illegal argument)";
logger.error(errorMsg, iaex);
throw new ServiceException(errorMsg);
} catch (Exception ex) {
String errorMsg = "Could not load docs for community.";
logger.error(errorMsg + " id " + communityID, ex);
throw new ServiceException(errorMsg);
}
}
public List<DocumentDTO> getDocumentsFromUser(String userID) {...}
@Override
public List<DocumentDTO> getDocumentsFromUser(String userID) {
try {
List<Document> documents;
User user = userDAO.getByUserId(userID);
if (user == null) throw new IllegalArgumentException("user must not be empty");
documents = documentDAO.findByUser(user);
return documents.stream().map(DocumentMapper::toDTO).collect(Collectors.toList());
} catch (IllegalArgumentException iaex) {
String errorMsg = "Could not load documents from user (illegal argument)";
logger.error(errorMsg, iaex);
throw new ServiceException(errorMsg);
} catch (Exception ex) {
String errorMsg = String.format("Could not load documents from user %s.", userID);
logger.error(errorMsg, ex);
throw new ServiceException(errorMsg);
}
}
public void removeDocument(Long documentID) {...}
@Override
public void removeDocument(Long documentID) {
String filename = "";
Document document;
try {
if (documentID <= 0) throw new IllegalArgumentException("documentID must not be zero");
document = documentDAO.findById(documentID);
if (document == null)
throw new IllegalArgumentException("document must not be empty (id " + documentID + ")");
filename = document.getFilename();
Long communityId = document.getDocumentlibrary().getCommunity().getId();
documentDAO.delete(document);
User user = document.getUser();
String msgText = "Removed Document " + filename;
addMessageToStream(communityId, user, msgText, document);
} catch (IllegalArgumentException iaex) {
String errorMsg = "Could not remove document (illegal argument)";
logger.error(errorMsg, iaex);
throw new ServiceException(errorMsg);
} catch (Exception ex) {
String errorMsg = String.format("Could not remove document %s.", filename);
logger.error(errorMsg, ex);
throw new ServiceException(errorMsg);
}
}
@Override
public DocumentDTO getDocumentById(Long documentID) {
try {
Document document = documentDAO.findById(documentID);
return DocumentMapper.toDTO(document);
} catch (Exception ex) {
String errorMsg = "Could not load document.";
logger.error(errorMsg + " id " + documentID, ex);
throw new ServiceException(errorMsg);
}
}
public DocumentDTO getDocumentById(Long documentID) {...}
}
\end{minted}
\begin{figure}[!htp]
\centering
\includegraphics[width=0.45\textwidth]{pics/sl_pat1.jpg}
\includegraphics[width=0.45\textwidth]{pics/sl_pat2.jpg}
\includegraphics[width=0.8\textwidth]{pics/sl_pat1.jpg}
\end{figure}
\subsection{Nenne die Konsequenzen der Anwendung}
\begin{itemize}
@ -295,26 +200,33 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
\item gut für Remote Aufrufe geeignet (weniger Aufrufe)
\end{itemize}
\section{Model-View-Controller Pattern}
\section{Model-View-Controller (MVC) Pattern}
\subsection{Erkläre die Funktion + Skizze}
MVC unterteilt eine interaktive Applikation in drei Teile: Model, View und Controller.
\begin{itemize}
\item Controller und View befinden sich im Presentation Layer und haben gegenseitig Abhängigkeiten
\item Das Model darf keine Abhängigkeiten haben (Controller und View hängen vom Model ab)
\end{itemize}
\begin{figure}[!htp]
\centering
\includegraphics[width=0.5\textwidth]{pics/mvc_pat.jpg}
\includegraphics[width=0.8\textwidth]{pics/mvc_pat.jpg}
\end{figure}
\subsubsection{Model}
\begin{itemize}
\item MVC unterteilt eine interaktive Applikation in drei Teile:
\begin{itemize}
\item Model (ServiceLayer): Kenfunktionalität und Daten (z.B.: Datenbankzugriff)
\item View (WebApp >> xhtml Dateien): Visualisierung bzw. User-Interaktion
\item Controller (web): enthält Logik und behandelt Benutzereingaben
\end{itemize}
\item Controller und View befinden sich im Presentation Layer und haben gegenseitig Abhängigkeiten
\item Model darf keine Abhängigkeiten haben (Controller und View hängen vom Model ab)
\item Es befinden sich Teile im Domain und Data Source Layer.
\item Das Model enthält die Kernfunktionalität und Daten. (z.B.: Datenbankzugriff)
\item Im Projekt ... % TODO
\end{itemize}
\subsubsection{View}
\begin{itemize}
\item Im Projekt im Ordner WebApp zu finden.
\item Enthält im Projekt xhtml Dateien zur Darstellung und User Interaktion
\end{itemize}
\subsubsection{Controller}
\begin{itemize}
\item Im Projekt sind Controllerklassen im Ordner web zu finden.
\item Sie enthalten die Logik und behandeln Benutzereingaben
\end{itemize}
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{pics/webapp-location.jpg}
\end{figure}
\subsection{Nenne die Konsequenzen der Anwendung}
\begin{itemize}
\item Visualisierung abhängig vom Model - nicht umgekehrt
@ -344,6 +256,7 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
\subsection{Beschreibe ein konkretes Anwendungsbeispiel}
\begin{itemize}
\item Java Server Faces (bei Java Server Faces enthält das File zwar keinen Java Code, interagiert aber direkt mit Java Code einer Backing Bean)
\item Im Projekt wurde der Front Controller in Form eines Servlet realisiert. Dieses ist im
\end{itemize}
\begin{minted}[linenos,breaklines=true]{xml}
<?xml version="1.0" encoding="UTF-8"?>