gfouquet avatar gfouquet committed 0318f31

[BSR] Reduced logging-induced string concatenation

Comments (0)

Files changed (8)

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/CampaignViewInterceptor.java

 import org.springframework.web.context.request.WebRequest;
 import org.squashtest.csp.core.domain.Identified;
 import org.squashtest.csp.tm.domain.campaign.Campaign;
+
 /**
  * 
  * @author mpagnon
- *
+ * 
  */
 public class CampaignViewInterceptor extends ObjectViewsInterceptor {
 
-	private static final Logger LOGGER = LoggerFactory.getLogger(CampaignViewInterceptor.class); 	
+	private static final Logger LOGGER = LoggerFactory.getLogger(CampaignViewInterceptor.class);
 
 	@Override
 	public void preHandle(WebRequest request) {
-		
+
 	}
 
 	@Override
 	public void postHandle(WebRequest request, ModelMap model) {
-		//check model is not null in case we are intercepting an ajax request on the campaign page
-		if (model != null) {Identified identified = (Identified) model.get("campaign");
+		// check model is not null in case we are intercepting an ajax request on the campaign page
+		if (model != null) {
+			Identified identified = (Identified) model.get("campaign");
 			if (identified != null) {
-				LOGGER.debug("New view added for Campaign = " + identified.getId() + " Viewer = "
-						+ request.getRemoteUser());
-				LOGGER.trace("Campaign request  description " + request.getDescription(true));
-	     boolean otherViewers = super.addViewerToEntity(Campaign.class.getSimpleName(), identified, request.getRemoteUser());
-	     model.addAttribute("otherViewers", otherViewers);
+				if (LOGGER.isTraceEnabled()) {
+					LOGGER.trace("Campaign request  description {}", request.getDescription(true));
+				}
+				boolean otherViewers = super.addViewerToEntity(Campaign.class.getSimpleName(), identified,
+						request.getRemoteUser());
+				model.addAttribute("otherViewers", otherViewers);
+			}
 		}
-       }
 	}
 
 	@Override

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/ExecutionViewInterceptor.java

 
 	@Override
 	public void preHandle(WebRequest request) {
-
+		// NOOP
 	}
 
 	@Override
 	public void postHandle(WebRequest request, ModelMap model) {
-
 		// check model is not null in case we are intercepting an ajax request on the page
 		if (model != null) {
 			Identified identified = (Identified) model.get("execution");
 			if (identified != null) {
-				LOGGER.debug("New view added for Execution = " + identified.getId() + " Viewer = "
-						+ request.getRemoteUser());
-				LOGGER.trace("Execution request  description " + request.getDescription(true));
+				if (LOGGER.isTraceEnabled()) {
+					LOGGER.trace("Execution request  description {}", request.getDescription(true));
+				}
 				boolean otherViewers = super.addViewerToEntity(Execution.class.getSimpleName(), identified,
 						request.getRemoteUser());
 				model.addAttribute("otherViewers", otherViewers);
 
 	@Override
 	public void afterCompletion(WebRequest request, Exception ex) {
-
+		// NOOP
 	}
 
 }

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/IterationViewInterceptor.java

 
 	@Override
 	public void postHandle(WebRequest request, ModelMap model) {
-
 		// check model is not null in case we are intercepting an ajax request on the page
 		if (model != null) {
 			Identified identified = (Identified) model.get("iteration");
 			if (identified != null) {
-				LOGGER.debug("New view added for Iteration = " + identified.getId() + " Viewer = "
-						+ request.getRemoteUser());
-				LOGGER.trace("Iteration request  description " + request.getDescription(true));
+				if (LOGGER.isTraceEnabled()) {
+					LOGGER.trace("Iteration request  description {}", request.getDescription(true));
+				}
 				boolean otherViewers = super.addViewerToEntity(Iteration.class.getSimpleName(), identified,
 						request.getRemoteUser());
 				model.addAttribute("otherViewers", otherViewers);

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/ObjectViewsInterceptor.java

 	private PermissionEvaluationService permissionService;
 
 	public boolean addViewerToEntity(String contextAttributeName, Identified object, String userLogin) {
+		LOGGER.debug("New view added for {} = {}  Viewer = {}", new Object[] {contextAttributeName, object.getId(), userLogin});
 		boolean otherViewers = false;
 		if (permissionService.hasMoreThanRead(object)) {
 			LOGGER.debug("User has more than readonly in object = true");

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/OpenedEntities.java

 import org.squashtest.csp.tm.domain.execution.Execution;
 import org.squashtest.csp.tm.domain.requirement.Requirement;
 import org.squashtest.csp.tm.domain.testcase.TestCase;
+
 /**
- * Opened Entities represent a list of object of one type among the "MANAGED_ENTITIES_LIST". 
- * It is used to notify a user if he is not the only one with to view the element. 
- * <br><br>
- * For example an OpenedEntities for TestCases will store , for each test-case is viewed, an entry in the "entitiesViewers" map with it's id as the key.
- * The OpenedEntity value will store the informations of how many users are viewing the test-case and how many views he has opened.
- * <br><br>
+ * Opened Entities represent a list of object of one type among the "MANAGED_ENTITIES_LIST". It is used to notify a user
+ * if he is not the only one with to view the element. <br>
+ * <br>
+ * For example an OpenedEntities for TestCases will store , for each test-case is viewed, an entry in the
+ * "entitiesViewers" map with it's id as the key. The OpenedEntity value will store the informations of how many users
+ * are viewing the test-case and how many views he has opened. <br>
+ * <br>
  * <b>How to add an object as a managed entity ? </b>
- * <ol> <li>create an <span style="color:darkgreen">interceptor</span> in the same model as that extends the ObjectViewsInterceptor. 
- * 	declare it in the <span style="color:darkgreen">servlet.xml</span> and map it to the rightful url, make sure the url will return a mav with the object of interest in it.
- * 	handle the opening of a new view and add the boolean "otherViewers" to the mav. </li>
- * <li>add the <span style="color:darkgreen">component "opened-object"</span> in the view to notify the user if he is not alone viewing this object and to send a quit request if the user leaves the view</li>
- * <li>add the leaveObject method in the <span style="color:darkgreen">ObjectAccessController</span> </li>
- * <li>add the object class.simpleName to the <span style="color:darkgreen">MANAGED_ENTITIES_LIST</span> below</li>. This will allow the OpenedEntitiesLifecycleListener to create the needed OpenedEntities at the start of squash and to close the view of a user the end of his session</ol>
+ * <ol>
+ * <li>create an <span style="color:darkgreen">interceptor</span> in the same model as that extends the
+ * ObjectViewsInterceptor. declare it in the <span style="color:darkgreen">servlet.xml</span> and map it to the rightful
+ * url, make sure the url will return a mav with the object of interest in it. handle the opening of a new view and add
+ * the boolean "otherViewers" to the mav.</li>
+ * <li>add the <span style="color:darkgreen">component "opened-object"</span> in the view to notify the user if he is
+ * not alone viewing this object and to send a quit request if the user leaves the view</li>
+ * <li>add the leaveObject method in the <span style="color:darkgreen">ObjectAccessController</span></li>
+ * <li>add the object class.simpleName to the <span style="color:darkgreen">MANAGED_ENTITIES_LIST</span> below</li>.
+ * This will allow the OpenedEntitiesLifecycleListener to create the needed OpenedEntities at the start of squash and to
+ * close the view of a user the end of his session
+ * </ol>
  * <br>
  * <b>How to add a view to a managed entity</b>
- * <ol><li>add the view's access url to the rightful interceptor in the <span style="color:darkgreen">serlvet.xml</span></li>
- * <li>make sure <span style="color:darkgreen">the object is returned in the mav</span> with the same name as in the other hanldled views</li>
+ * <ol>
+ * <li>add the view's access url to the rightful interceptor in the <span style="color:darkgreen">serlvet.xml</span></li>
+ * <li>make sure <span style="color:darkgreen">the object is returned in the mav</span> with the same name as in the
+ * other hanldled views</li>
  * <li>add the <span style="color:darkgreen">component "opened-object"</span> in the view</li>
  * </ol>
  * 
  * @author mpagnon
- *
+ * 
  */
 public class OpenedEntities {
 	private static final Logger LOGGER = LoggerFactory.getLogger(OpenedEntities.class);
-	
+
 	private Map<Long, OpenedEntity> entitiesViewers;
-	
+
 	public static final List<String> MANAGED_ENTITIES_LIST = Arrays.asList(TestCase.class.getSimpleName(),
-			Requirement.class.getSimpleName(), Campaign.class.getSimpleName(), Iteration.class.getSimpleName(), TestSuite.class.getSimpleName(), Execution.class.getSimpleName());
+			Requirement.class.getSimpleName(), Campaign.class.getSimpleName(), Iteration.class.getSimpleName(),
+			TestSuite.class.getSimpleName(), Execution.class.getSimpleName());
 
-	public OpenedEntities(){
+	public OpenedEntities() {
 		entitiesViewers = new HashMap<Long, OpenedEntity>();
 	}
-	
+
 	public synchronized boolean addViewerToEntity(Identified object, String userLogin) {
-		//get the entity || create one if none
+		// get the entity || create one if none
 		OpenedEntity openedEntity = findOpenedEntity(object);
-		
-		//add viewer to entity and return true if viewer is not the only one
+
+		// add viewer to entity and return true if viewer is not the only one
 		return openedEntity.addViewForViewer(userLogin);
 	}
-	
-	
+
 	private synchronized OpenedEntity findOpenedEntity(Identified object) {
 		OpenedEntity openedEntity = this.entitiesViewers.get(object.getId());
-		if(openedEntity == null){
-			LOGGER.debug("Entity was not listed => new Entity");
+		if (openedEntity == null) {
+			LOGGER.trace("Entity was not listed => new Entity");
 			openedEntity = new OpenedEntity();
 			this.entitiesViewers.put(object.getId(), openedEntity);
-		}else{
-			LOGGER.debug("Entity was already listed");
+		} else {
+			LOGGER.trace("Entity was already listed");
 		}
 		return openedEntity;
 	}
-	
-	
-	public synchronized void removeViewer(String viewerLogin){
-		for(Entry<Long, OpenedEntity> entityViewers : entitiesViewers.entrySet()){
+
+	public synchronized void removeViewer(String viewerLogin) {
+		for (Entry<Long, OpenedEntity> entityViewers : entitiesViewers.entrySet()) {
 			OpenedEntity openedEntity = entityViewers.getValue();
 			openedEntity.removeAllViewsForViewer(viewerLogin);
 		}
 
 	public synchronized void removeView(String name, Long id) {
 		OpenedEntity openedEntity = this.entitiesViewers.get(id);
-		if(openedEntity != null){
+		if (openedEntity != null) {
 			openedEntity.removeViewForViewer(name);
 		}
-		
+
 	}
 }

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/RequirementViewInterceptor.java

 		if (model != null) {
 			Identified identified = (Identified) model.get("requirement");
 			if (identified != null) {
-				LOGGER.debug("New view added for Requirement = " + identified.getId() + " Viewer = "
-						+ request.getRemoteUser());
-				LOGGER.trace("Requirement request  description " + request.getDescription(true));
+				if (LOGGER.isTraceEnabled()) {
+					LOGGER.trace("Requirement request  description " + request.getDescription(true));
+				}
 				boolean otherViewers = super.addViewerToEntity(Requirement.class.getSimpleName(), identified,
 						request.getRemoteUser());
 				model.addAttribute("otherViewers", otherViewers);

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/TestCaseViewInterceptor.java

 		if (model != null) {
 			Identified tc = (Identified) model.get("testCase");
 			if (tc != null) {
-				LOGGER.debug("New view added for TestCase = " + tc.getId() + " Viewer = " + request.getRemoteUser());
-				LOGGER.trace("TestCase request  description " + request.getDescription(true));
+				if (LOGGER.isTraceEnabled()) {
+					LOGGER.trace("TestCase request  description " + request.getDescription(true));
+				}
 				boolean otherViewers = super.addViewerToEntity(TestCase.class.getSimpleName(), tc,
 						request.getRemoteUser());
 				model.addAttribute("otherViewers", otherViewers);
 
 	@Override
 	public void afterCompletion(WebRequest request, Exception ex) {
-		
+
 	}
 
 }

tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/TestSuiteViewInterceptor.java

 		if (model != null) {
 			Identified identified = (Identified) model.get("testSuite");
 			if (identified != null) {
-				LOGGER.debug("New view added for TestSuite = " + identified.getId() + " Viewer = "
-						+ request.getRemoteUser());
-				LOGGER.trace("TestSuite request  description " + request.getDescription(true));
+				if (LOGGER.isTraceEnabled()) {
+					LOGGER.trace("TestSuite request  description " + request.getDescription(true));
+				}
 				boolean otherViewers = super.addViewerToEntity(TestSuite.class.getSimpleName(), identified,
 						request.getRemoteUser());
 				model.addAttribute("otherViewers", otherViewers);
 
 	@Override
 	public void afterCompletion(WebRequest request, Exception ex) {
-		
+
 	}
 
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.