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} \end{itemize}
\section{Service Layer Pattern (auch Session Fassade)}\label{sec:slp} \section{Service Layer Pattern (auch Session Fassade)}\label{sec:slp}
\subsection{Erkläre die Funktion + Skizze}\label{subsubsec:service-layer-pattern} \subsection{Erkläre die Funktion + Skizze}\label{subsubsec:service-layer-pattern}
\begin{itemize} \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 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 (z.B. Zeile 39), Error (z.B. Zeile 42-50) und Validierungshandling (z.B.: Zeile 24-27) im Service erledigt \item Bei wenig Logik wird zumindest Transaktions (Zeile 40), Error (ab Zeile 42) und Validierungshandling (ab Zeile 23) im Service erledigt
\end{itemize} \end{itemize}
\begin{minted}[xleftmargin=\parindent,linenos,breaklines=true]{java} \begin{minted}[xleftmargin=\parindent,linenos,breaklines=true]{java}
@Local(DocumentService.class) @Local(DocumentService.class)
@ -125,6 +124,7 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
Document addedDocument; Document addedDocument;
User user; User user;
// Validierungshandling gefolgt von Error Handling
try { try {
if (communityID <= 0) throw new IllegalArgumentException("community must not be empty"); if (communityID <= 0) throw new IllegalArgumentException("community must not be empty");
if (userID == null) throw new IllegalArgumentException("user 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); user = userDAO.getByUserId(userID);
addedDocument = new Document(documentlibrary, user, filename, data); addedDocument = new Document(documentlibrary, user, filename, data);
documentDAO.insert(addedDocument); documentDAO.insert(addedDocument); // Transaktionshandling
logger.info(String.format("Document %s saved in database", filename)); logger.info(String.format("Document %s saved in database", filename));
// Error Handling
} catch (IllegalArgumentException iaex) { } catch (IllegalArgumentException iaex) {
String errorMsg = "Uploading file failed (illegal argument)"; String errorMsg = "Uploading file failed (illegal argument)";
logger.error(errorMsg, iaex); 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) { 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 Documentlibrary addDocumentlibrary(Long communityID) { private Documentlibrary addDocumentlibrary(Long communityID) {
logger.info("Create missing documentlibrary"); logger.info("Create missing documentlibrary");
Community community; Community community;
Documentlibrary documentlibrary = new Documentlibrary(); Documentlibrary documentlibrary = new Documentlibrary();
documentlibraryDAO.insert(documentlibrary); documentlibraryDAO.insert(documentlibrary); // Delegation zum DAO
community = communityDAO.findById(communityID); community = communityDAO.findById(communityID); // Delegation zum DAO
community.setDocumentlibrary(documentlibrary); community.setDocumentlibrary(documentlibrary); // Delegation zur Business Logik (Entity)
communityDAO.update(community); communityDAO.update(community); // Delegation zum DAO
return documentlibrary; return documentlibrary;
} }
@Override
public List<DocumentDTO> getDocumentsFromCommunity(Long communityID) {...}
@Override @Override
public List<DocumentDTO> getDocumentsFromCommunity(Long communityID) { public List<DocumentDTO> getDocumentsFromUser(String userID) {...}
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);
}
}
@Override @Override
public List<DocumentDTO> getDocumentsFromUser(String userID) { public void removeDocument(Long documentID) {...}
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);
}
}
@Override @Override
public void removeDocument(Long documentID) { public DocumentDTO getDocumentById(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);
}
}
} }
\end{minted} \end{minted}
\begin{figure}[!htp] \begin{figure}[!htp]
\centering \centering
\includegraphics[width=0.45\textwidth]{pics/sl_pat1.jpg} \includegraphics[width=0.8\textwidth]{pics/sl_pat1.jpg}
\includegraphics[width=0.45\textwidth]{pics/sl_pat2.jpg}
\end{figure} \end{figure}
\subsection{Nenne die Konsequenzen der Anwendung} \subsection{Nenne die Konsequenzen der Anwendung}
\begin{itemize} \begin{itemize}
@ -295,26 +200,33 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
\item gut für Remote Aufrufe geeignet (weniger Aufrufe) \item gut für Remote Aufrufe geeignet (weniger Aufrufe)
\end{itemize} \end{itemize}
\section{Model-View-Controller Pattern} \section{Model-View-Controller (MVC) Pattern}
\subsection{Erkläre die Funktion + Skizze} \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] \begin{figure}[!htp]
\centering \centering
\includegraphics[width=0.5\textwidth]{pics/mvc_pat.jpg} \includegraphics[width=0.8\textwidth]{pics/mvc_pat.jpg}
\end{figure} \end{figure}
\subsubsection{Model}
\begin{itemize} \begin{itemize}
\item MVC unterteilt eine interaktive Applikation in drei Teile: \item Es befinden sich Teile im Domain und Data Source Layer.
\begin{itemize} \item Das Model enthält die Kernfunktionalität und Daten. (z.B.: Datenbankzugriff)
\item Model (ServiceLayer): Kenfunktionalität und Daten (z.B.: Datenbankzugriff) \item Im Projekt ... % TODO
\item View (WebApp >> xhtml Dateien): Visualisierung bzw. User-Interaktion \end{itemize}
\item Controller (web): enthält Logik und behandelt Benutzereingaben \subsubsection{View}
\end{itemize} \begin{itemize}
\item Controller und View befinden sich im Presentation Layer und haben gegenseitig Abhängigkeiten \item Im Projekt im Ordner WebApp zu finden.
\item Model darf keine Abhängigkeiten haben (Controller und View hängen vom Model ab) \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} \end{itemize}
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{pics/webapp-location.jpg}
\end{figure}
\subsection{Nenne die Konsequenzen der Anwendung} \subsection{Nenne die Konsequenzen der Anwendung}
\begin{itemize} \begin{itemize}
\item Visualisierung abhängig vom Model - nicht umgekehrt \item Visualisierung abhängig vom Model - nicht umgekehrt
@ -344,6 +256,7 @@ public class DocumentDAOImpl implements DocumentDAO, Serializable {
\subsection{Beschreibe ein konkretes Anwendungsbeispiel} \subsection{Beschreibe ein konkretes Anwendungsbeispiel}
\begin{itemize} \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 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} \end{itemize}
\begin{minted}[linenos,breaklines=true]{xml} \begin{minted}[linenos,breaklines=true]{xml}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>