Skip to content

Commit

Permalink
#444 loggers improved
Browse files Browse the repository at this point in the history
  • Loading branch information
iratigarzon committed Aug 21, 2024
1 parent b76f49f commit e14e81b
Show file tree
Hide file tree
Showing 22 changed files with 213 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import eu.europa.ec.re3gistry2.crudimplementation.RegActionManager;
import eu.europa.ec.re3gistry2.model.RegAction;
import java.io.IOException;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -62,7 +63,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
try {
regAction = regActionManager.get(actionUUID);
} catch (NoResultException e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within ActionDetail class. Please check the details: " + e.getMessage(), e.getMessage());
}

// Setting the RegAction parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.logging.Level;

@WebServlet(WebConstants.PAGE_URINAME_ADDITEM)
public class AddItem extends HttpServlet {

private void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Init logger
Logger logger = Configuration.getInstance().getLogger();
Logger logger = Configuration.getInstance().getLogger();

// Init frontend servlet
Configuration.getInstance().initServlet(request, response, false, false);
Expand Down Expand Up @@ -99,14 +101,13 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
String newItemItemclassUuid = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_NEWITEMREGITEMCLASSUUID);
String formRegItemContainerUuid = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_REGITEMCONTAINERUUID);
String externalItem = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_EXTERNAL_ITEM);

languageUuid = (languageUuid != null) ? InputSanitizerHelper.sanitizeInput(languageUuid) : null;
itemUuid = (itemUuid != null) ? InputSanitizerHelper.sanitizeInput(itemUuid) : null;
formNewItemCheck = (formNewItemCheck != null) ? InputSanitizerHelper.sanitizeInput(formNewItemCheck) : null;
newItemItemclassUuid = (newItemItemclassUuid != null) ? InputSanitizerHelper.sanitizeInput(newItemItemclassUuid) : null;
formRegItemContainerUuid = (formRegItemContainerUuid != null) ? InputSanitizerHelper.sanitizeInput(formRegItemContainerUuid) : null;
externalItem = (externalItem != null) ? InputSanitizerHelper.sanitizeInput(externalItem) : null;

externalItem = (externalItem != null) ? InputSanitizerHelper.sanitizeInput(externalItem) : null;

if (itemUuid == null || itemUuid.length() < 1) {
itemUuid = formRegItemContainerUuid;
Expand All @@ -123,7 +124,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp

// Getting the language by parameter (if not available the master language is used)
RegLanguagecode regLanguagecode = null;

// Adding a new item it always add in the masterLanguage
/*if (languageUuid != null && languageUuid.length() == 2) {
try {
Expand All @@ -132,7 +133,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
regLanguagecode = masterLanguage;
}
} else {*/
regLanguagecode = masterLanguage;
regLanguagecode = masterLanguage;
//}
request.setAttribute(BaseConstants.KEY_REQUEST_CURRENTLANGUAGE, regLanguagecode);

Expand All @@ -153,6 +154,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
try {
regItemRegistry = regRelationRegistries.get(0).getRegItemObject();
} catch (Exception e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.INFO, e.getMessage(), e.getMessage());
regItemRegistry = null;
}
}
Expand All @@ -164,6 +166,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
try {
regItemRegister = regRelationRegisters.get(0).getRegItemObject();
} catch (Exception e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.INFO, e.getMessage(), e.getMessage());
regItemRegister = null;
}
}
Expand Down Expand Up @@ -224,20 +227,19 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp

// Getting the request's parameters
Map requestParameters = request.getParameterMap();

// Dispatch the rerquest
try {
regItemproposedHandler.handleRegItemproposedAddition(requestParameters, regUser, localization);
} catch (Exception e) {
String operationResult = e.getMessage();
request.setAttribute(BaseConstants.KEY_REQUEST_OPERATIONRESULT, operationResult);
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddItem class. Please check the details: " + e.getMessage(), e.getMessage());

}

// Redirecting to the Item container page
request.getRequestDispatcher("." + WebConstants.PAGE_URINAME_BROWSE + "?" + BaseConstants.KEY_REQUEST_ITEMUUID + "=" + itemUuid + "&" + BaseConstants.KEY_REQUEST_LANGUAGEUUID + "=" + languageUuid).forward(request, response);


} else {

Expand Down Expand Up @@ -289,6 +291,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_ADDITEM + WebConstants.PAGE_URINAME_ADDITEM + WebConstants.PAGE_JSP_EXTENSION).forward(request, response);

} catch (Exception e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddItem class. Please check the details: " + e.getMessage(), e.getMessage());
// Redirecting to the Item container page
response.sendRedirect("." + WebConstants.PAGE_URINAME_BROWSE + "?" + BaseConstants.KEY_REQUEST_ITEMUUID + "=" + itemUuid);
}
Expand All @@ -298,10 +301,11 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
response.sendRedirect("." + WebConstants.PAGE_URINAME_BROWSE + "?" + BaseConstants.KEY_REQUEST_ITEMUUID + "=" + itemUuid);
}
} catch (NoResultException e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddItem class. Please check the details: " + e.getMessage(), e.getMessage());
// Redirecting to the Item container page
response.sendRedirect("." + WebConstants.PAGE_URINAME_BROWSE + "?" + BaseConstants.KEY_REQUEST_ITEMUUID + "=" + itemUuid);
} catch (Exception e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddItem class. Please check the details: " + e.getMessage(), e.getMessage());
}
} else {
response.sendRedirect("." + WebConstants.PAGE_URINAME_BROWSE);
Expand All @@ -314,7 +318,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
processRequest(request, response);
} catch (Exception ex) {
Logger logger = Configuration.getInstance().getLogger();
logger.error(ex.getMessage(), ex);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddItem class. Please check the details: " + ex.getMessage(), ex.getMessage());
}
}

Expand All @@ -324,7 +328,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
processRequest(request, response);
} catch (Exception ex) {
Logger logger = Configuration.getInstance().getLogger();
logger.error(ex.getMessage(), ex);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddItem class. Please check the details: " + ex.getMessage(), ex.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.ResourceBundle;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -178,7 +179,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
}

} catch (NoResultException e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within AddRegister class. Please check the details: " + e.getMessage(), e.getMessage());
// Setting the operation success attribute
operationResult = localization.getString("error.generic");
request.setAttribute(BaseConstants.KEY_REQUEST_OPERATIONRESULT, operationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -90,7 +91,8 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
mainRegistryItemclassLocalId = properties.getProperty("application.multiregistry.mainregistryitemclasslocalid");
mainRegistryLocalId = properties.getProperty("application.multiregistry.mainregistrylocalid");
} catch (Exception e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Browse class. Please check the details: " + e.getMessage(), e.getMessage());

}

// Setup the entity manager
Expand Down Expand Up @@ -310,7 +312,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
try {
regItemproposedHandler.handleRegItemproposedSave(requestParameters, regUser);
} catch (Exception e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Browse class. Please check the details: " + e.getMessage(), e.getMessage());
saveError = true;
}
} else if (regItemproposed != null && ( // Permission to edit Registers and items
Expand All @@ -328,7 +330,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
try {
regItemproposedHandler.handleRegItemproposedNewSave(requestParameters, regUser);
} catch (Exception e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Browse class. Please check the details: " + e.getMessage(), e.getMessage());
saveError = true;
}
}
Expand Down Expand Up @@ -385,7 +387,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Browse class. Please check the details: " + e.getMessage(), e.getMessage());
response.sendRedirect(".");
} finally {
if (entityManager.isOpen()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
request.getRequestDispatcher("." + WebConstants.PAGE_URINAME_BROWSE + "?" + BaseConstants.KEY_REQUEST_ITEMUUID + "=" + itemUuid + "&" + BaseConstants.KEY_REQUEST_LANGUAGEUUID + "=" + languageUuid).forward(request, response);
}
} catch (Exception ex) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within BulkImport class. Please check the details: " + ex.getMessage(), ex.getMessage());
// request.setAttribute(BaseConstants.KEY_REQUEST_BULK_ERROR, ex.getMessage());
request.getRequestDispatcher("." + WebConstants.PAGE_URINAME_BROWSE + "?" + BaseConstants.KEY_REQUEST_ITEMUUID + "=" + itemUuid + "&" + BaseConstants.KEY_REQUEST_LANGUAGEUUID + "=" + languageUuid).forward(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.logging.Level;
import javax.mail.internet.InternetAddress;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
Expand Down Expand Up @@ -272,6 +273,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
}

} catch (NoResultException e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within ControlBody class. Please check the details: " + e.getMessage(), e.getMessage());
}
}

Expand All @@ -295,6 +297,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp

} catch (Exception e) {
// Redirecting to the RegItemclasses list page
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within ControlBody class. Please check the details: " + e.getMessage(), e.getMessage());
response.sendRedirect("." + WebConstants.PAGE_PATH_INDEX + WebConstants.PAGE_URINAME_INDEX);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import eu.europa.ec.re3gistry2.web.utility.jsp.JspCommon;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -146,7 +147,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
redirectURI = "." + WebConstants.PAGE_PATH_SUBMITTINGORGANISATIONS + WebConstants.PAGE_URINAME_SUBMITTINGORGANISATIONS;
// request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_SUBMITTINGORGANISATIONS + WebConstants.PAGE_URINAME_SUBMITTINGORGANISATIONS + WebConstants.PAGE_JSP_EXTENSION).forward(request, response);
} catch (NoResultException e) {
logger.error(e.getMessage(), e);
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within DiscardProposal class. Please check the details: " + e.getMessage(), e.getMessage());
}
} else // discard item
if (regItemproposedUUID != null && !regItemproposedUUID.isEmpty()) {
Expand Down Expand Up @@ -226,6 +227,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
response.sendRedirect(redirectURI);

} catch (NoResultException e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within DiscardProposal class. Please check the details: " + e.getMessage(), e.getMessage());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand Down Expand Up @@ -164,6 +165,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
try {
newPositionValue = Integer.parseInt(formNewPosition);
} catch (Exception e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Field class. Please check the details: " + e.getMessage(), e.getMessage());
}

// Updating the order
Expand All @@ -184,6 +186,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
RegField regField = regFieldManager.get(fieldUuid);
request.setAttribute(BaseConstants.KEY_REQUEST_REGFIELD, regField);
} catch (Exception e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Field class. Please check the details: " + e.getMessage(), e.getMessage());
request.setAttribute(BaseConstants.KEY_REQUEST_REGFIELD, null);
}
} else {
Expand Down Expand Up @@ -220,6 +223,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
// Dispatch request
request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_FIELD + WebConstants.PAGE_URINAME_FIELD + WebConstants.PAGE_JSP_EXTENSION).forward(request, response);
} catch (Exception e) {
java.util.logging.Logger.getLogger(RegisterManager.class.getName()).log(Level.SEVERE, "Error encountered within Field class. Please check the details: " + e.getMessage(), e.getMessage());
response.sendRedirect("." + WebConstants.PAGE_URINAME_ITEMCLASS);
}
} else {
Expand Down
Loading

0 comments on commit e14e81b

Please sign in to comment.