From 91d3e65fdd476c64d932a2a1207df734f4536d4c Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 2 Feb 2014 22:13:13 +0100 Subject: [PATCH] Log the debug and trace messages only if the Logger is set on debug or trace level --- .../baasbox/configuration/Application.java | 4 +- .../configuration/IosCertificateHandler.java | 6 +- app/com/baasbox/configuration/Push.java | 2 +- app/com/baasbox/controllers/Admin.java | 44 +++--- app/com/baasbox/controllers/Document.java | 128 +++++++++--------- app/com/baasbox/controllers/File.java | 10 +- app/com/baasbox/controllers/Generic.java | 2 +- app/com/baasbox/controllers/Push.java | 12 +- app/com/baasbox/controllers/Social.java | 2 +- app/com/baasbox/controllers/User.java | 58 ++++---- .../filters/AdminCredentialWrapFilter.java | 16 +-- .../AnonymousCredentialWrapFilter.java | 14 +- .../actions/filters/AnonymousLogin.java | 6 +- .../actions/filters/BasicAuthAccess.java | 20 +-- .../actions/filters/CheckAdminRoleFilter.java | 8 +- .../actions/filters/ConnectToDBFilter.java | 14 +- .../filters/ExtractQueryParameters.java | 8 +- .../actions/filters/InjectSession.java | 4 +- .../filters/NoUserCredentialWrapFilter.java | 6 +- .../actions/filters/RequestHeaderHelper.java | 6 +- .../actions/filters/SessionTokenAccess.java | 18 +-- .../filters/UserCredentialWrapFilter.java | 10 +- .../UserOrAnonymousCredentialsFilter.java | 10 +- .../actions/filters/WrapResponse.java | 16 +-- app/com/baasbox/dao/CollectionDao.java | 12 +- app/com/baasbox/dao/DocumentDao.java | 4 +- app/com/baasbox/dao/GenericDao.java | 4 +- app/com/baasbox/dao/NodeDao.java | 34 ++--- app/com/baasbox/dao/PermissionsHelper.java | 40 +++--- app/com/baasbox/dao/UserDao.java | 2 +- app/com/baasbox/db/DbHelper.java | 44 +++--- app/com/baasbox/db/Evolution_0_7_3.java | 4 +- app/com/baasbox/db/hook/Audit.java | 12 +- app/com/baasbox/db/hook/HooksManager.java | 22 +-- .../security/SessionTokenProvider.java | 4 +- app/com/baasbox/service/push/PushService.java | 14 +- .../service/push/providers/APNServer.java | 2 +- .../service/push/providers/GCMServer.java | 2 +- .../sociallogin/SocialLoginService.java | 2 +- .../sociallogin/TwitterLoginService.java | 2 +- .../service/storage/StatisticsService.java | 26 ++-- app/com/baasbox/service/user/RoleService.java | 2 +- app/com/baasbox/service/user/UserService.java | 6 +- app/com/baasbox/util/QueryParams.java | 12 +- app/com/baasbox/util/Util.java | 6 +- test/AdminImportTest.java | 2 +- test/AdminUserChangePasswordTest.java | 4 +- test/UserChangePasswordTest.java | 4 +- 48 files changed, 345 insertions(+), 345 deletions(-) diff --git a/app/com/baasbox/configuration/Application.java b/app/com/baasbox/configuration/Application.java index 37da48b0..c7b2da07 100644 --- a/app/com/baasbox/configuration/Application.java +++ b/app/com/baasbox/configuration/Application.java @@ -43,7 +43,7 @@ public void change(final Object iCurrentValue, final Object iNewValue){ public void setValue(Object newValue) { Object parsedValue=null; - Logger.debug("New setting value, key: " + this.key + ", type: "+ this.type + ", new value: " + newValue); + if (Logger.isDebugEnabled()) Logger.debug("New setting value, key: " + this.key + ", type: "+ this.type + ", new value: " + newValue); if (newValue != null) if (type == Boolean.class) parsedValue = Boolean.parseBoolean(newValue.toString()); @@ -71,7 +71,7 @@ public Object getValue() { IndexApplicationConfiguration idx; try { idx = new IndexApplicationConfiguration(); - Logger.debug("getting "+key+" from index"); + if (Logger.isDebugEnabled()) Logger.debug("getting "+key+" from index"); return idx.get(key); } catch (Exception e) { Logger.error("Could not retrieve key " + key, e); diff --git a/app/com/baasbox/configuration/IosCertificateHandler.java b/app/com/baasbox/configuration/IosCertificateHandler.java index f7aab68b..d100b1a8 100644 --- a/app/com/baasbox/configuration/IosCertificateHandler.java +++ b/app/com/baasbox/configuration/IosCertificateHandler.java @@ -43,7 +43,7 @@ public void change(Object iCurrentValue, Object iNewValue) { try { currentValue =new ObjectMapper().readValue(iCurrentValue.toString(), ConfigurationFileContainer.class); } catch (Exception e) { - Logger.debug("unable to convert value to ConfigurationFileContainer"); + if (Logger.isDebugEnabled()) Logger.debug("unable to convert value to ConfigurationFileContainer"); } }else if (iCurrentValue instanceof ConfigurationFileContainer){ currentValue = (ConfigurationFileContainer)iCurrentValue; @@ -95,7 +95,7 @@ public static void init(){ ConfigurationFileContainer prod = Push.PRODUCTION_IOS_CERTIFICATE.getValueAsFileContainer(); ConfigurationFileContainer sandbox = Push.SANDBOX_IOS_CERTIFICATE.getValueAsFileContainer(); if(prod!=null){ - Logger.debug("Creating production certificate:"+prod.getName()); + if (Logger.isDebugEnabled()) Logger.debug("Creating production certificate:"+prod.getName()); File prodCertificate = new File(Play.application().path().getAbsolutePath()+sep+folder+sep+prod.getName()); if(!prodCertificate.exists()){ try{ @@ -110,7 +110,7 @@ public static void init(){ } } if(sandbox!=null){ - Logger.debug("Creating sandbox certificate:"+sandbox.getName()); + if (Logger.isDebugEnabled()) Logger.debug("Creating sandbox certificate:"+sandbox.getName()); File sandboxCertificate = new File(Play.application().path().getAbsolutePath()+sep+folder+sep+sandbox.getName()); if(!sandboxCertificate.exists()){ try{ diff --git a/app/com/baasbox/configuration/Push.java b/app/com/baasbox/configuration/Push.java index 69305739..48d8375a 100644 --- a/app/com/baasbox/configuration/Push.java +++ b/app/com/baasbox/configuration/Push.java @@ -40,7 +40,7 @@ public enum Push implements IProperties{ @Override public void setValue(Object newValue) { Object parsedValue=null; - Logger.debug("Type:"+type+" Setting "+newValue.toString() + "of class: "+newValue.getClass().toString()); + if (Logger.isDebugEnabled()) Logger.debug("Type:"+type+" Setting "+newValue.toString() + "of class: "+newValue.getClass().toString()); try{ if (newValue != null) if (type == Boolean.class) diff --git a/app/com/baasbox/controllers/Admin.java b/app/com/baasbox/controllers/Admin.java index 9bbad6a8..68ef2460 100644 --- a/app/com/baasbox/controllers/Admin.java +++ b/app/com/baasbox/controllers/Admin.java @@ -110,7 +110,7 @@ public class Admin extends Controller { static String fileSeparator = System.getProperty("file.separator")!=null?System.getProperty("file.separator"):"/"; public static Result getUsers(){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Context ctx=Http.Context.current.get(); QueryParams criteria = (QueryParams) ctx.args.get(IQueryParametersKeys.QUERY_PARAMETERS); List users=null; @@ -125,13 +125,13 @@ public static Result getUsers(){ }catch (Throwable e){ return internalServerError(ExceptionUtils.getFullStackTrace(e)); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); response().setContentType("application/json"); return ok(ret); } public static Result getUser(String username){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Context ctx=Http.Context.current.get(); ODocument user=null; @@ -147,13 +147,13 @@ public static Result getUser(String username){ }catch (Throwable e){ return internalServerError(ExceptionUtils.getFullStackTrace(e)); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); response().setContentType("application/json"); return ok(ret); } public static Result getCollections(){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); List result; String ret="{[]}"; @@ -172,13 +172,13 @@ public static Result getCollections(){ return internalServerError(ExceptionUtils.getFullStackTrace(e)); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); response().setContentType("application/json"); return ok(ret); } public static Result createCollection(String name) throws Throwable{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); try{ CollectionService.create(name); }catch (CollectionAlreadyExistsException e) { @@ -191,7 +191,7 @@ public static Result createCollection(String name) throws Throwable{ Logger.error(ExceptionUtils.getFullStackTrace(e)); throw e; } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return created(); } @@ -317,11 +317,11 @@ public static Result getRole(String name) throws SqlInjectionException{ /* create user in any role */ public static Result createUser(){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.debug("signUp bodyJson: " + bodyJson); + if (Logger.isDebugEnabled()) Logger.debug("signUp bodyJson: " + bodyJson); //check and validate input if (!bodyJson.has("username")) @@ -362,17 +362,17 @@ public static Result createUser(){ Logger.error(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e) ; } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return created(); }//createUser public static Result updateUser(String username){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.debug("signUp bodyJson: " + bodyJson); + if (Logger.isDebugEnabled()) Logger.debug("signUp bodyJson: " + bodyJson); if (!bodyJson.has("role")) return badRequest("The 'role' field is missing"); @@ -434,7 +434,7 @@ public static Result updateUser(String username){ if (Play.isDev()) return internalServerError(ExceptionUtils.getFullStackTrace(e)); else return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(user.toJSON(Formats.USER.toString())); }//updateUser @@ -446,10 +446,10 @@ public static Result updateUser(String username){ * @throws SqlInjectionException */ public static Result changePassword(String username) throws SqlInjectionException, UserNotFoundException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); //{"password":"Password"} - Logger.trace("changePassword bodyJson: " + bodyJson); + if (Logger.isTraceEnabled()) Logger.trace("changePassword bodyJson: " + bodyJson); if (bodyJson==null) return badRequest("The body payload cannot be empty."); JsonNode passwordNode=bodyJson.findValue("password"); @@ -463,7 +463,7 @@ public static Result changePassword(String username) throws SqlInjectionExceptio Logger.error("Username not found " + username, e); return notFound("Username not found"); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(); } @@ -481,7 +481,7 @@ public static Result dropUser(){ * @return */ public static Result dropCollection(String name){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); try { CollectionService.drop(name); }catch (SqlInjectionException e){ @@ -492,7 +492,7 @@ public static Result dropCollection(String name){ Logger.error(ExceptionUtils.getFullStackTrace(e)); return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); response().setContentType("application/json"); return ok(); } @@ -551,7 +551,7 @@ public static Result getConfiguration(String section) throws Throwable{ public static Result getLatestVersion() { String urlToCall="http://www.baasbox.com/version/"+ Internal.INSTALLATION_ID.getValueAsString() + "/"; - Logger.debug("Calling " + urlToCall); + if (Logger.isDebugEnabled()) Logger.debug("Calling " + urlToCall); final Promise promise = WS.url(urlToCall).get(); return status(promise.get().getStatus(),promise.get().getBody()); }//getLatestVersion @@ -754,7 +754,7 @@ public static Result importDb(){ if (version.compareToIgnoreCase("0.6.0")<0){ //we support imports from version 0.6.0 return badRequest(String.format("Current baasbox version(%s) is not compatible with import file version(%s)",BBConfiguration.getApiVersion(),version)); }else{ - Logger.debug("Version : "+version+" is valid"); + if (Logger.isDebugEnabled()) Logger.debug("Version : "+version+" is valid"); } }else{ return badRequest("The manifest file does not contain a version number"); @@ -762,7 +762,7 @@ public static Result importDb(){ }else{ return badRequest("Looks like zip file does not contain a manifest file"); } - Logger.debug("Importing: "+fileContent); + if (Logger.isDebugEnabled()) Logger.debug("Importing: "+fileContent); if(fileContent!=null && StringUtils.isNotEmpty(fileContent.trim())){ DbHelper.importData(appcode, fileContent); zis.closeEntry(); diff --git a/app/com/baasbox/controllers/Document.java b/app/com/baasbox/controllers/Document.java index 1a49b3c7..cc820ca2 100644 --- a/app/com/baasbox/controllers/Document.java +++ b/app/com/baasbox/controllers/Document.java @@ -90,31 +90,31 @@ private static String prepareResponseToJson(List listOfDoc) throws IO */ @With ({UserOrAnonymousCredentialsFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result getCount(String collectionName){ - Logger.trace("Method Start"); - Logger.trace("collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("collectionName: " + collectionName); long count; try { Context ctx=Http.Context.current.get(); QueryParams criteria = (QueryParams) ctx.args.get(IQueryParametersKeys.QUERY_PARAMETERS); count = DocumentService.getCount(collectionName,criteria); - Logger.trace("count: " + count); + if (Logger.isTraceEnabled()) Logger.trace("count: " + count); } catch (InvalidCollectionException e) { - Logger.debug (collectionName + " is not a valid collection name"); + if (Logger.isDebugEnabled()) Logger.debug (collectionName + " is not a valid collection name"); return notFound(collectionName + " is not a valid collection name"); } catch (Exception e){ Logger.error(ExceptionUtils.getFullStackTrace(e)); return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); response().setContentType("application/json"); return ok("{\"count\": "+ count +" }"); } @With ({UserOrAnonymousCredentialsFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result getDocuments(String collectionName){ - Logger.trace("Method Start"); - Logger.trace("collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("collectionName: " + collectionName); List result; String ret="{[]}"; @@ -122,9 +122,9 @@ public static Result getDocuments(String collectionName){ Context ctx=Http.Context.current.get(); QueryParams criteria = (QueryParams) ctx.args.get(IQueryParametersKeys.QUERY_PARAMETERS); result = DocumentService.getDocuments(collectionName,criteria); - Logger.trace("count: " + result.size()); + if (Logger.isTraceEnabled()) Logger.trace("count: " + result.size()); } catch (InvalidCollectionException e) { - Logger.debug (collectionName + " is not a valid collection name"); + if (Logger.isDebugEnabled()) Logger.debug (collectionName + " is not a valid collection name"); return notFound(collectionName + " is not a valid collection name"); } catch (Exception e){ Logger.error(ExceptionUtils.getFullStackTrace(e)); @@ -137,18 +137,18 @@ public static Result getDocuments(String collectionName){ return internalServerError(ExceptionUtils.getFullStackTrace(e)); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(ret); } private static String getRidByString(String id , boolean isUUID) throws RidNotFoundException { String rid=null; if (isUUID) { - Logger.debug("id is an UUID, try to get a valid RID"); + if (Logger.isDebugEnabled()) Logger.debug("id is an UUID, try to get a valid RID"); ORID orid=GenericDao.getInstance().getRidByUUID(id); if (orid==null) throw new RidNotFoundException(id); rid = orid.toString(); - Logger.debug("Retrieved RID: " + rid); + if (Logger.isDebugEnabled()) Logger.debug("Retrieved RID: " + rid); }else rid="#"+id; return rid; } @@ -159,9 +159,9 @@ public static Result queryDocument(String collectionName,String id,boolean isUUI if(parts==null || StringUtils.isEmpty(parts)){ return getDocument(collectionName, id, isUUID); } else{ - Logger.trace("Method Start"); - Logger.trace("collectionName: " + collectionName); - Logger.trace("rid: " + id); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("rid: " + id); ODocument doc; try { String[] tokens = parts.split("/"); @@ -196,7 +196,7 @@ public static Result queryDocument(String collectionName,String id,boolean isUUI } catch (InvalidCriteriaException e) { return badRequest(e.getMessage()!=null?e.getMessage():""); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToObjectJson(doc)); } @@ -204,9 +204,9 @@ public static Result queryDocument(String collectionName,String id,boolean isUUI @With ({UserOrAnonymousCredentialsFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result getDocument(String collectionName, String id, boolean isUUID){ - Logger.trace("Method Start"); - Logger.trace("collectionName: " + collectionName); - Logger.trace("rid: " + id); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("rid: " + id); ODocument doc; try { String rid = getRidByString(id, isUUID); @@ -225,16 +225,16 @@ public static Result getDocument(String collectionName, String id, boolean isUUI } catch (RidNotFoundException e) { return notFound(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToJson(doc)); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result getDocumentByRid(String rid){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); rid="#"+rid; - Logger.trace("rid: " + rid); + if (Logger.isTraceEnabled()) Logger.trace("rid: " + rid); ODocument doc; try { doc=DocumentService.get(rid); @@ -244,7 +244,7 @@ public static Result getDocumentByRid(String rid){ }catch (ODatabaseException e){ return notFound(rid + " unknown"); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToJson(doc)); } @@ -252,37 +252,37 @@ public static Result getDocumentByRid(String rid){ @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) @BodyParser.Of(BodyParser.Json.class) public static Result createDocument(String collection){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.trace("creating document in collection: " + collection); - Logger.trace("bodyJson: " + bodyJson); + if (Logger.isTraceEnabled()) Logger.trace("creating document in collection: " + collection); + if (Logger.isTraceEnabled()) Logger.trace("bodyJson: " + bodyJson); if (bodyJson==null) return badRequest("The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); ODocument document; try{ document=DocumentService.create(collection, bodyJson); - Logger.trace("Document created: " + document.getRecord().getIdentity()); + if (Logger.isTraceEnabled()) Logger.trace("Document created: " + document.getRecord().getIdentity()); }catch (InvalidCollectionException e){ return notFound(e.getMessage()); }catch (Throwable e){ Logger.error(ExceptionUtils.getFullStackTrace(e)); return internalServerError(ExceptionUtils.getFullStackTrace(e)); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToJson(document)); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) @BodyParser.Of(BodyParser.Json.class) public static Result updateDocument(String collectionName, String id, boolean isUUID){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); if (bodyJson==null) return badRequest("The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); if (bodyJson.get("@version")!=null && !bodyJson.get("@version").isInt()) return badRequest("@version field must be an Integer"); - Logger.trace("updateDocument collectionName: " + collectionName); - Logger.trace("updateDocument id: " + id); + if (Logger.isTraceEnabled()) Logger.trace("updateDocument collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("updateDocument id: " + id); ODocument document=null; try{ String rid=getRidByString(id,isUUID); @@ -308,18 +308,18 @@ public static Result updateDocument(String collectionName, String id, boolean is return internalServerError(ExceptionUtils.getFullStackTrace(e)); } if (document==null) return notFound("Document " + id + " was not found in the collection " + collectionName); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToJson(document)); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) @BodyParser.Of(BodyParser.Json.class) public static Result updateDocumentWithParts(String collectionName, String id, boolean isUUID,String parts){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.trace("updateDocument collectionName: " + collectionName); - Logger.trace("updateDocument id: " + id); + if (Logger.isTraceEnabled()) Logger.trace("updateDocument collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("updateDocument id: " + id); if (bodyJson==null) return badRequest("The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); if (bodyJson.get("data")==null) return badRequest("The body payload must have a data field. Hint: modify your content to have a \"data\" field"); ODocument document=null; @@ -358,15 +358,15 @@ public static Result updateDocumentWithParts(String collectionName, String id, b return internalServerError(ExceptionUtils.getFullStackTrace(e)); } if (document==null) return notFound("Document " + id + " was not found in the collection " + collectionName); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToJson(document)); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result deleteDocument(String collectionName, String id, boolean isUUID){ - Logger.trace("Method Start"); - Logger.trace("deleteDocument collectionName: " + collectionName); - Logger.trace("deleteDocument rid: " + id); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("deleteDocument collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("deleteDocument rid: " + id); try { String rid=getRidByString(id,isUUID); DocumentService.delete(collectionName,rid); @@ -379,55 +379,55 @@ public static Result deleteDocument(String collectionName, String id, boolean is } catch (Throwable e ){ internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(""); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result grantToUser(String collectionName, String rid, String username, String action, boolean isUUID){ - Logger.trace("Method Start"); - Logger.trace("grant collectionName: " + collectionName); - Logger.trace("grant rid: " + rid); - Logger.trace("grant username: " + username); - Logger.trace("grant action: " + action); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("grant collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("grant rid: " + rid); + if (Logger.isTraceEnabled()) Logger.trace("grant username: " + username); + if (Logger.isTraceEnabled()) Logger.trace("grant action: " + action); Result res=grantOrRevokeToUser(collectionName,rid,username,action,true, isUUID); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return res; } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result revokeToUser(String collectionName, String rid, String username, String action, boolean isUUID){ - Logger.trace("Method Start"); - Logger.trace("grant collectionName: " + collectionName); - Logger.trace("grant rid: " + rid); - Logger.trace("grant username: " + username); - Logger.trace("grant action: " + action); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("grant collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("grant rid: " + rid); + if (Logger.isTraceEnabled()) Logger.trace("grant username: " + username); + if (Logger.isTraceEnabled()) Logger.trace("grant action: " + action); Result res=grantOrRevokeToUser(collectionName,rid,username,action,false, isUUID); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return res; } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result grantToRole(String collectionName, String rid, String rolename, String action, boolean isUUID){ - Logger.trace("Method Start"); - Logger.trace("grant collectionName: " + collectionName); - Logger.trace("grant rid: " + rid); - Logger.trace("grant rolename: " + rolename); - Logger.trace("grant action: " + action); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("grant collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("grant rid: " + rid); + if (Logger.isTraceEnabled()) Logger.trace("grant rolename: " + rolename); + if (Logger.isTraceEnabled()) Logger.trace("grant action: " + action); Result res=grantOrRevokeToRole(collectionName,rid,rolename,action,true, isUUID); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return res; } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result revokeToRole(String collectionName, String rid, String rolename, String action, boolean isUUID){ - Logger.trace("Method Start"); - Logger.trace("grant collectionName: " + collectionName); - Logger.trace("grant rid: " + rid); - Logger.trace("grant rolename: " + rolename); - Logger.trace("grant action: " + action); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("grant collectionName: " + collectionName); + if (Logger.isTraceEnabled()) Logger.trace("grant rid: " + rid); + if (Logger.isTraceEnabled()) Logger.trace("grant rolename: " + rolename); + if (Logger.isTraceEnabled()) Logger.trace("grant action: " + action); Result res=grantOrRevokeToRole(collectionName,rid,rolename,action,false, isUUID); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return res; } diff --git a/app/com/baasbox/controllers/File.java b/app/com/baasbox/controllers/File.java index 70d4d787..148e16e5 100644 --- a/app/com/baasbox/controllers/File.java +++ b/app/com/baasbox/controllers/File.java @@ -204,13 +204,13 @@ public static Result storeFile() throws Throwable { for (String key:metadata.names()){ try{ if (metadata.isMultiValued(key)){ - Logger.debug(key + ": "); + if (Logger.isDebugEnabled()) Logger.debug(key + ": "); for (String value: metadata.getValues(key)){ - Logger.debug(" " + value); + if (Logger.isDebugEnabled()) Logger.debug(" " + value); } extractedMetaData.put(key.replace(":", "_").replace(" ", "_").trim(), Arrays.asList(metadata.getValues(key))); }else{ - Logger.debug(key + ": " + metadata.get(key)); + if (Logger.isDebugEnabled()) Logger.debug(key + ": " + metadata.get(key)); extractedMetaData.put(key.replace(":", "_").replace(" ", "_").trim(), metadata.get(key)); } }catch(Throwable e){ @@ -219,8 +219,8 @@ public static Result storeFile() throws Throwable { } - Logger.debug("................................."); - Logger.debug(new JSONObject(extractedMetaData).toString()); + if (Logger.isDebugEnabled()) Logger.debug("................................."); + if (Logger.isDebugEnabled()) Logger.debug(new JSONObject(extractedMetaData).toString()); is.close(); is=new FileInputStream(fileContent); diff --git a/app/com/baasbox/controllers/Generic.java b/app/com/baasbox/controllers/Generic.java index 95c5d9c7..71a5b5d3 100644 --- a/app/com/baasbox/controllers/Generic.java +++ b/app/com/baasbox/controllers/Generic.java @@ -15,7 +15,7 @@ public static Result getOptions(String parameter){ response().setHeader("Allow", "OPTIONS, GET, POST, PUT, DELETE"); response().setHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE"); response().setHeader("Access-Control-Allow-Origin", "*"); - Logger.debug(Json.stringify(Json.toJson(request().headers()))); + if (Logger.isDebugEnabled()) Logger.debug(Json.stringify(Json.toJson(request().headers()))); if (request().getHeader("ACCESS-CONTROL-REQUEST-HEADERS")!=null) response().setHeader("Access-Control-Allow-Headers",request().getHeader("ACCESS-CONTROL-REQUEST-HEADERS")); return ok(); diff --git a/app/com/baasbox/controllers/Push.java b/app/com/baasbox/controllers/Push.java index cd0a2114..7bc10e12 100644 --- a/app/com/baasbox/controllers/Push.java +++ b/app/com/baasbox/controllers/Push.java @@ -40,10 +40,10 @@ @BodyParser.Of(BodyParser.Json.class) public class Push extends Controller { public static Result send(String username) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); //{"message":"Text"} - Logger.trace("send bodyJson: " + bodyJson); + if (Logger.isTraceEnabled()) Logger.trace("send bodyJson: " + bodyJson); if (bodyJson==null) return badRequest("The body payload cannot be empty."); JsonNode messageNode=bodyJson.findValue("message"); if (messageNode==null) return badRequest("The body payload doesn't contain key message"); @@ -75,20 +75,20 @@ public static Result send(String username) { } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(); } public static Result enablePush(String os, String deviceId) throws SqlInjectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if(os==null) return badRequest("Os value doesn't not null"); if(deviceId==null) return badRequest("DeviceId value doesn't not null"); - Logger.debug("Trying to enable push to os: "+os+" deviceId: "+ deviceId); + if (Logger.isDebugEnabled()) Logger.debug("Trying to enable push to os: "+os+" deviceId: "+ deviceId); HashMap data = new HashMap(); data.put("os",os); data.put("deviceId", deviceId); UserService.registerDevice(data); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(); } diff --git a/app/com/baasbox/controllers/Social.java b/app/com/baasbox/controllers/Social.java index c2eb13e4..abba0558 100644 --- a/app/com/baasbox/controllers/Social.java +++ b/app/com/baasbox/controllers/Social.java @@ -125,7 +125,7 @@ public static Result loginWith(String socialNetwork){ on.put(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); return ok(on); }else{ - Logger.debug("User does not exists with tokens...trying to create"); + if (Logger.isDebugEnabled()) Logger.debug("User does not exists with tokens...trying to create"); String username = UUID.randomUUID().toString(); Date signupDate = new Date(); try{ diff --git a/app/com/baasbox/controllers/User.java b/app/com/baasbox/controllers/User.java index d5760422..8c2acc53 100644 --- a/app/com/baasbox/controllers/User.java +++ b/app/com/baasbox/controllers/User.java @@ -122,29 +122,29 @@ static String prepareResponseToJson(List listOfDoc) { */ @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class}) public static Result getCurrentUser() throws SqlInjectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODocument profile = UserService.getCurrentUser(); String result=prepareResponseToJson(profile); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(result); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class}) public static Result getUser(String username) throws SqlInjectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (ArrayUtils.contains( new String[]{ BBConfiguration.getBaasBoxAdminUsername() , BBConfiguration.getBaasBoxUsername()}, username)) return badRequest(username + " cannot be queried"); ODocument profile = UserService.getUserProfilebyUsername(username); if (profile==null) return notFound(username + " not found"); String result=prepareResponseToJson(profile); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(result); } @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class,ExtractQueryParameters.class}) public static Result getUsers() { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Context ctx=Http.Context.current.get(); QueryParams criteria = (QueryParams) ctx.args.get(IQueryParametersKeys.QUERY_PARAMETERS); String where="user.name not in ?" ; @@ -163,18 +163,18 @@ public static Result getUsers() { return badRequest(ExceptionUtils.getMessage(e) + " -- " + ExceptionUtils.getRootCauseMessage(e)); } String result=prepareResponseToJson(profiles); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(result); } @With ({AdminCredentialWrapFilter.class, ConnectToDBFilter.class}) @BodyParser.Of(BodyParser.Json.class) public static Result signUp() throws JsonProcessingException, IOException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.trace("signUp bodyJson: " + bodyJson); + if (Logger.isTraceEnabled()) Logger.trace("signUp bodyJson: " + bodyJson); if (bodyJson==null) return badRequest("The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); //check and validate input if (!bodyJson.has("username")) @@ -202,14 +202,14 @@ public static Result signUp() throws JsonProcessingException, IOException{ try { profile = UserService.signUp(username, password,null, nonAppUserAttributes, privateAttributes, friendsAttributes, appUsersAttributes,false); } catch (UserAlreadyExistsException e){ - Logger.debug("signUp", e); + if (Logger.isDebugEnabled()) Logger.debug("signUp", e); return badRequest(username + " already exists"); } catch (Throwable e){ Logger.warn("signUp", e); if (Play.isDev()) return internalServerError(ExceptionUtils.getFullStackTrace(e)); else return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); ImmutableMap sessionObject = SessionTokenProvider.getSessionTokenProvider().setSession(appcode, username, password); response().setHeader(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); @@ -224,11 +224,11 @@ public static Result signUp() throws JsonProcessingException, IOException{ @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class}) @BodyParser.Of(BodyParser.Json.class) public static Result updateProfile(){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.trace("updateProfile bodyJson: " + bodyJson); + if (Logger.isTraceEnabled()) Logger.trace("updateProfile bodyJson: " + bodyJson); if (bodyJson==null) return badRequest("The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); //extract the profile fields @@ -251,7 +251,7 @@ public static Result updateProfile(){ if (Play.isDev()) return internalServerError(ExceptionUtils.getFullStackTrace(e)); else return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(prepareResponseToJson(profile)); }//updateProfile @@ -272,7 +272,7 @@ public static Result exists(String username){ @With ({AdminCredentialWrapFilter.class, ConnectToDBFilter.class}) public static Result resetPasswordStep1(String username){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); //check and validate input if (username == null) @@ -301,7 +301,7 @@ public static Result resetPasswordStep1(String username){ if (Play.isDev()) return internalServerError(ExceptionUtils.getFullStackTrace(e)); else return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(); } @@ -319,7 +319,7 @@ public static Result resetPasswordStep2(String base64) throws ResetPasswordExcep try{ tokenReceived = new String(Base64.decodeBase64(base64.getBytes())); - Logger.debug("resetPasswordStep2 - sRandom: " + tokenReceived); + if (Logger.isDebugEnabled()) Logger.debug("resetPasswordStep2 - sRandom: " + tokenReceived); //token format should be APP_Code%%%%Username%%%%ResetTokenId String[] tokens = tokenReceived.split("%%%%"); @@ -380,7 +380,7 @@ public static Result resetPasswordStep3(String base64) { //loads the received token and extracts data by the hashcode in the url tokenReceived = new String(Base64.decodeBase64(base64.getBytes())); - Logger.debug("resetPasswordStep3 - sRandom: " + tokenReceived); + if (Logger.isDebugEnabled()) Logger.debug("resetPasswordStep3 - sRandom: " + tokenReceived); //token format should be APP_Code%%%%Username%%%%ResetTokenId String[] tokens = tokenReceived.split("%%%%"); @@ -456,7 +456,7 @@ public static Result resetPasswordStep3(String base64) { if (Play.isDev()) return internalServerError(ExceptionUtils.getFullStackTrace(e)); else return internalServerError(e.getMessage()); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); String ok_message = "Password changed"; ST pageTemplate = new ST(PasswordRecovery.PAGE_HTML_FEEDBACK_TEMPLATE.getValueAsString(), '$', '$'); @@ -471,11 +471,11 @@ public static Result resetPasswordStep3(String base64) { @With ({UserCredentialWrapFilter.class,ConnectToDBFilter.class}) @BodyParser.Of(BodyParser.Json.class) public static Result changePassword(){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson= body.asJson(); - Logger.trace("changePassword bodyJson: " + bodyJson); + if (Logger.isTraceEnabled()) Logger.trace("changePassword bodyJson: " + bodyJson); if (bodyJson==null) return badRequest("The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); //check and validate input @@ -493,7 +493,7 @@ public static Result changePassword(){ } UserService.changePasswordCurrentUser(newPassword); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ok(); } @@ -543,9 +543,9 @@ public static Result login() throws SqlInjectionException, JsonProcessingExcepti else password=body.get("password")[0]; if(body.get("appcode")==null) return badRequest("The 'appcode' field is missing"); else appcode=body.get("appcode")[0]; - Logger.debug("Username " + username); - Logger.debug("Password " + password); - Logger.debug("Appcode " + appcode); + if (Logger.isDebugEnabled()) Logger.debug("Username " + username); + if (Logger.isDebugEnabled()) Logger.debug("Password " + password); + if (Logger.isDebugEnabled()) Logger.debug("Appcode " + appcode); if (username.equalsIgnoreCase(BBConfiguration.getBaasBoxAdminUsername()) || username.equalsIgnoreCase(BBConfiguration.getBaasBoxUsername()) @@ -553,7 +553,7 @@ public static Result login() throws SqlInjectionException, JsonProcessingExcepti if (body.get("login_data")!=null) loginData=body.get("login_data")[0]; - Logger.debug("LoginData" + loginData); + if (Logger.isDebugEnabled()) Logger.debug("LoginData" + loginData); /* other useful parameter to receive and to store...*/ //validate user credentials @@ -569,8 +569,8 @@ public static Result login() throws SqlInjectionException, JsonProcessingExcepti try{ loginInfo = Json.parse(loginData); }catch(Exception e){ - Logger.debug ("Error parsong login_data field"); - Logger.debug (ExceptionUtils.getFullStackTrace(e)); + if (Logger.isDebugEnabled()) Logger.debug ("Error parsong login_data field"); + if (Logger.isDebugEnabled()) Logger.debug (ExceptionUtils.getFullStackTrace(e)); return badRequest("login_data field is not a valid json string"); } Iterator> it =loginInfo.getFields(); @@ -584,10 +584,10 @@ public static Result login() throws SqlInjectionException, JsonProcessingExcepti UserService.registerDevice(data); } }catch (OSecurityAccessException e){ - Logger.debug("UserLogin: " + e.getMessage()); + if (Logger.isDebugEnabled()) Logger.debug("UserLogin: " + e.getMessage()); return unauthorized("user " + username + " unauthorized"); } catch (InvalidAppCodeException e) { - Logger.debug("UserLogin: " + e.getMessage()); + if (Logger.isDebugEnabled()) Logger.debug("UserLogin: " + e.getMessage()); return badRequest("user " + username + " unauthorized"); }finally{ if (db!=null && !db.isClosed()) db.close(); diff --git a/app/com/baasbox/controllers/actions/filters/AdminCredentialWrapFilter.java b/app/com/baasbox/controllers/actions/filters/AdminCredentialWrapFilter.java index 7984d618..003e8143 100644 --- a/app/com/baasbox/controllers/actions/filters/AdminCredentialWrapFilter.java +++ b/app/com/baasbox/controllers/actions/filters/AdminCredentialWrapFilter.java @@ -37,10 +37,10 @@ public class AdminCredentialWrapFilter extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { Result tempResult=null; - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); - Logger.debug("AdminCredentialWrapFilter for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("AdminCredentialWrapFilter for resource " + Http.Context.current().request()); //retrieve AppCode String appCode=RequestHeaderHelper.getAppCode(ctx); //try to retrieve from querystring @@ -54,13 +54,13 @@ public Result call(Context ctx) throws Throwable { ctx.args.put("password", adminPassword); ctx.args.put("appcode", appCode); - Logger.debug("admin username (defined in conf file): " + adminUser); - Logger.debug("admin password (defined in conf file): " + adminPassword); - Logger.debug("appcode (from header): " + appCode); - Logger.debug("token: N/A"); + if (Logger.isDebugEnabled()) Logger.debug("admin username (defined in conf file): " + adminUser); + if (Logger.isDebugEnabled()) Logger.debug("admin password (defined in conf file): " + adminPassword); + if (Logger.isDebugEnabled()) Logger.debug("appcode (from header): " + appCode); + if (Logger.isDebugEnabled()) Logger.debug("token: N/A"); if (appCode == null || appCode.isEmpty() || appCode.equals("null")){ - Logger.debug("Invalid App Code, AppCode is empty!"); + if (Logger.isDebugEnabled()) Logger.debug("Invalid App Code, AppCode is empty!"); tempResult= badRequest("Invalid App Code. AppCode is empty or not set"); } @@ -73,7 +73,7 @@ public Result call(Context ctx) throws Throwable { Result result=wr.wrap(ctx, tempResult); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/AnonymousCredentialWrapFilter.java b/app/com/baasbox/controllers/actions/filters/AnonymousCredentialWrapFilter.java index f8098bbf..b4f9338c 100644 --- a/app/com/baasbox/controllers/actions/filters/AnonymousCredentialWrapFilter.java +++ b/app/com/baasbox/controllers/actions/filters/AnonymousCredentialWrapFilter.java @@ -30,10 +30,10 @@ public class AnonymousCredentialWrapFilter extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); - Logger.debug("AnonymousLogin for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("AnonymousLogin for resource " + Http.Context.current().request()); String user=BBConfiguration.getBaasBoxUsername(); String password = BBConfiguration.getBaasBoxPassword(); @@ -45,10 +45,10 @@ public Result call(Context ctx) throws Throwable { ctx.args.put("password", password); ctx.args.put("appcode", appCode); - Logger.debug("username (defined in conf file): " + user); - Logger.debug("password (defined in conf file): " + password); - Logger.debug("appcode (from header or querystring): " + appCode); - Logger.debug("token: N/A"); + if (Logger.isDebugEnabled()) Logger.debug("username (defined in conf file): " + user); + if (Logger.isDebugEnabled()) Logger.debug("password (defined in conf file): " + password); + if (Logger.isDebugEnabled()) Logger.debug("appcode (from header or querystring): " + appCode); + if (Logger.isDebugEnabled()) Logger.debug("token: N/A"); //executes the request Result tempResult = delegate.call(ctx); @@ -56,7 +56,7 @@ public Result call(Context ctx) throws Throwable { WrapResponse wr = new WrapResponse(); Result result=wr.wrap(ctx, tempResult); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/AnonymousLogin.java b/app/com/baasbox/controllers/actions/filters/AnonymousLogin.java index 2bfa4747..1b972f2e 100644 --- a/app/com/baasbox/controllers/actions/filters/AnonymousLogin.java +++ b/app/com/baasbox/controllers/actions/filters/AnonymousLogin.java @@ -29,10 +29,10 @@ public class AnonymousLogin extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); - Logger.debug("AnonymousLogin for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("AnonymousLogin for resource " + Http.Context.current().request()); String user=BBConfiguration.getBaasBoxUsername(); @@ -41,7 +41,7 @@ public Result call(Context ctx) throws Throwable { ctx.args.put("username", user); ctx.args.put("password", password); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return delegate.call(ctx); } diff --git a/app/com/baasbox/controllers/actions/filters/BasicAuthAccess.java b/app/com/baasbox/controllers/actions/filters/BasicAuthAccess.java index 78ae8a35..d09e5eeb 100644 --- a/app/com/baasbox/controllers/actions/filters/BasicAuthAccess.java +++ b/app/com/baasbox/controllers/actions/filters/BasicAuthAccess.java @@ -33,11 +33,11 @@ public class BasicAuthAccess implements IAccessMethod { @Override public boolean setCredential (Context ctx) { - Logger.trace("Method Start"); - Logger.debug("BasicAuthHeader for resource " + Http.Context.current().request()); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isDebugEnabled()) Logger.debug("BasicAuthHeader for resource " + Http.Context.current().request()); //retrieve AppCode String appcode=RequestHeaderHelper.getAppCode(ctx); - Logger.debug(SessionKeys.APP_CODE + ": " + appcode); + if (Logger.isDebugEnabled()) Logger.debug(SessionKeys.APP_CODE + ": " + appcode); ctx.args.put("appcode", appcode); String username = ""; @@ -48,12 +48,12 @@ public boolean setCredential (Context ctx) { //-------------------------------------------------------------- String authHeader = ctx.request().getHeader(AUTHORIZATION); if (authHeader == null) { - Logger.debug(AUTHORIZATION + " header is null or missing"); + if (Logger.isDebugEnabled()) Logger.debug(AUTHORIZATION + " header is null or missing"); return false; } String auth = authHeader.substring(6); - Logger.debug(AUTHORIZATION + ": " + auth); + if (Logger.isDebugEnabled()) Logger.debug(AUTHORIZATION + ": " + auth); byte[] decodedAuth; try { decodedAuth = new sun.misc.BASE64Decoder().decodeBuffer(auth); @@ -61,7 +61,7 @@ public boolean setCredential (Context ctx) { Logger.error("Cannot decode " + AUTHORIZATION + " header. ",e1); return false; } - Logger.debug ("Decoded header: " + decodedAuth); + if (Logger.isDebugEnabled()) Logger.debug ("Decoded header: " + decodedAuth); String[] credString; try { credString = new String(decodedAuth, "UTF-8").split(":"); @@ -71,20 +71,20 @@ public boolean setCredential (Context ctx) { } if (credString == null || credString.length != 2) { - Logger.debug(AUTHORIZATION + " header is not valid (has not user:password pair)"); + if (Logger.isDebugEnabled()) Logger.debug(AUTHORIZATION + " header is not valid (has not user:password pair)"); return false; } username = credString[0]; password = credString[1]; - Logger.debug("username: " + username); - Logger.debug("password: "); + if (Logger.isDebugEnabled()) Logger.debug("username: " + username); + if (Logger.isDebugEnabled()) Logger.debug("password: "); ctx.args.put("username", username); ctx.args.put("password", password); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return true; } diff --git a/app/com/baasbox/controllers/actions/filters/CheckAdminRoleFilter.java b/app/com/baasbox/controllers/actions/filters/CheckAdminRoleFilter.java index ffeeb437..ce3a9dc7 100644 --- a/app/com/baasbox/controllers/actions/filters/CheckAdminRoleFilter.java +++ b/app/com/baasbox/controllers/actions/filters/CheckAdminRoleFilter.java @@ -35,11 +35,11 @@ public class CheckAdminRoleFilter extends Action.Simple{ @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); - Logger.debug("CheckAdminRole for resource " + Http.Context.current().request()); - Logger.debug("CheckAdminRole user: " + ctx.args.get("username")); + if (Logger.isDebugEnabled()) Logger.debug("CheckAdminRole for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("CheckAdminRole user: " + ctx.args.get("username")); OUser user=DbHelper.getConnection().getUser(); Set roles=user.getRoles(); @@ -48,7 +48,7 @@ public Result call(Context ctx) throws Throwable { if (roles.contains(RoleDao.getRole(DefaultRoles.ADMIN.toString()))){ result = delegate.call(ctx); }else result=forbidden("User " + ctx.args.get("username") + " is not an administrator"); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/ConnectToDBFilter.java b/app/com/baasbox/controllers/actions/filters/ConnectToDBFilter.java index d7d8a8e1..99dcc900 100644 --- a/app/com/baasbox/controllers/actions/filters/ConnectToDBFilter.java +++ b/app/com/baasbox/controllers/actions/filters/ConnectToDBFilter.java @@ -39,11 +39,11 @@ public class ConnectToDBFilter extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); //set the current Context in the local thread to be used in the views: https://groups.google.com/d/msg/play-framework/QD3czEomKIs/LKLX24dOFKMJ Http.Context.current.set(ctx); - Logger.debug("ConnectToDB for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("ConnectToDB for resource " + Http.Context.current().request()); String username=(String) Http.Context.current().args.get("username"); String password=(String)Http.Context.current().args.get("password"); String appcode=(String)Http.Context.current().args.get("appcode"); @@ -54,7 +54,7 @@ public Result call(Context ctx) throws Throwable { try{ database=DbHelper.open(appcode,username,password); }catch (OSecurityAccessException e){ - Logger.debug(e.getMessage()); + if (Logger.isDebugEnabled()) Logger.debug(e.getMessage()); return unauthorized("User " + Http.Context.current().args.get("username") + " is not authorized to access"); }catch(ShuttingDownDBException sde){ String message = sde.getMessage(); @@ -65,19 +65,19 @@ public Result call(Context ctx) throws Throwable { result = delegate.call(ctx); }catch (OSecurityAccessException e){ - Logger.debug("ConnectToDB: user authenticated but a security exception against the resource has been detected: " + e.getMessage()); + if (Logger.isDebugEnabled()) Logger.debug("ConnectToDB: user authenticated but a security exception against the resource has been detected: " + e.getMessage()); result = forbidden(e.getMessage()); }catch (InvalidAppCodeException e){ - Logger.debug("ConnectToDB: Invalid App Code " + e.getMessage()); + if (Logger.isDebugEnabled()) Logger.debug("ConnectToDB: Invalid App Code " + e.getMessage()); result = unauthorized(e.getMessage()); }catch (Throwable e){ - Logger.debug("ConnectToDB: an expected error has been detected: "+ e.getMessage()); + if (Logger.isDebugEnabled()) Logger.debug("ConnectToDB: an expected error has been detected: "+ e.getMessage()); throw e; }finally{ Http.Context.current.set(ctx); DbHelper.close(database); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/ExtractQueryParameters.java b/app/com/baasbox/controllers/actions/filters/ExtractQueryParameters.java index d7779e0b..f3ca4c0d 100644 --- a/app/com/baasbox/controllers/actions/filters/ExtractQueryParameters.java +++ b/app/com/baasbox/controllers/actions/filters/ExtractQueryParameters.java @@ -29,15 +29,15 @@ public class ExtractQueryParameters extends Action.Simple{ @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); - Logger.debug("ExtractQueryParameters for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("ExtractQueryParameters for resource " + Http.Context.current().request()); QueryParams qryp =QueryParams.getParamsFromQueryString(Http.Context.current().request()); - Logger.debug("ExtractQueryParameters " + qryp); + if (Logger.isDebugEnabled()) Logger.debug("ExtractQueryParameters " + qryp); ctx.args.put(IQueryParametersKeys.QUERY_PARAMETERS, qryp); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return delegate.call(ctx); } diff --git a/app/com/baasbox/controllers/actions/filters/InjectSession.java b/app/com/baasbox/controllers/actions/filters/InjectSession.java index f2d83207..9dc47572 100644 --- a/app/com/baasbox/controllers/actions/filters/InjectSession.java +++ b/app/com/baasbox/controllers/actions/filters/InjectSession.java @@ -32,7 +32,7 @@ public class InjectSession extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); ctx.response().setHeader("Access-Control-Allow-Origin", "*"); @@ -51,7 +51,7 @@ public Result call(Context ctx) throws Throwable { //executes the request Result result = delegate.call(ctx); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/NoUserCredentialWrapFilter.java b/app/com/baasbox/controllers/actions/filters/NoUserCredentialWrapFilter.java index 67ee1b69..c236bab5 100644 --- a/app/com/baasbox/controllers/actions/filters/NoUserCredentialWrapFilter.java +++ b/app/com/baasbox/controllers/actions/filters/NoUserCredentialWrapFilter.java @@ -30,10 +30,10 @@ public class NoUserCredentialWrapFilter extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Http.Context.current.set(ctx); - Logger.debug("NoUserCredentialWrapFilter for resource " + Http.Context.current().request()); + if (Logger.isDebugEnabled()) Logger.debug("NoUserCredentialWrapFilter for resource " + Http.Context.current().request()); //executes the request Result tempResult = delegate.call(ctx); @@ -41,7 +41,7 @@ public Result call(Context ctx) throws Throwable { WrapResponse wr = new WrapResponse(); Result result=wr.wrap(ctx, tempResult); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/RequestHeaderHelper.java b/app/com/baasbox/controllers/actions/filters/RequestHeaderHelper.java index d39727f0..82890269 100644 --- a/app/com/baasbox/controllers/actions/filters/RequestHeaderHelper.java +++ b/app/com/baasbox/controllers/actions/filters/RequestHeaderHelper.java @@ -9,12 +9,12 @@ public class RequestHeaderHelper { public static String getAppCode(Context ctx){ //first guess if the appcode is present into the request header String appCode=ctx.request().getHeader(SessionKeys.APP_CODE.toString()); - Logger.debug("AppCode from header: " + appCode); + if (Logger.isDebugEnabled()) Logger.debug("AppCode from header: " + appCode); //If not, try to search into the querystring. Useful for GET on assets if (appCode==null || appCode.isEmpty()){ - Logger.debug("Appcode form header is empty, trying on QueryString"); + if (Logger.isDebugEnabled()) Logger.debug("Appcode form header is empty, trying on QueryString"); appCode=ctx.request().getQueryString(SessionKeys.APP_CODE.toString()); - Logger.debug("AppCode from queryString: " + appCode); + if (Logger.isDebugEnabled()) Logger.debug("AppCode from queryString: " + appCode); } if (appCode==null) Logger.warn(SessionKeys.APP_CODE.toString() + " is null"); return appCode; diff --git a/app/com/baasbox/controllers/actions/filters/SessionTokenAccess.java b/app/com/baasbox/controllers/actions/filters/SessionTokenAccess.java index 23aff8b4..4936bf4f 100644 --- a/app/com/baasbox/controllers/actions/filters/SessionTokenAccess.java +++ b/app/com/baasbox/controllers/actions/filters/SessionTokenAccess.java @@ -30,31 +30,31 @@ public class SessionTokenAccess implements IAccessMethod { @Override public boolean setCredential(Context ctx) { - Logger.debug("SessionTokenAccess"); + if (Logger.isDebugEnabled()) Logger.debug("SessionTokenAccess"); //injects the user data & credential into the context String token=ctx.request().getHeader(SessionKeys.TOKEN.toString()); if (StringUtils.isEmpty(token)) token = ctx.request().getQueryString(SessionKeys.TOKEN.toString()); if (token!=null) { - Logger.debug("Received session token " + token); + if (Logger.isDebugEnabled()) Logger.debug("Received session token " + token); ImmutableMap sessionData = SessionTokenProvider.getSessionTokenProvider().getSession(token); if (sessionData!=null){ - Logger.debug("Token identified: "); + if (Logger.isDebugEnabled()) Logger.debug("Token identified: "); ctx.args.put("username", sessionData.get(SessionKeys.USERNAME)); ctx.args.put("password", sessionData.get(SessionKeys.PASSWORD)); ctx.args.put("appcode", sessionData.get(SessionKeys.APP_CODE)); ctx.args.put("token", token); - Logger.debug("username: " + (String)sessionData.get(SessionKeys.USERNAME)); - Logger.debug("password: " ); - Logger.debug("appcode: " + (String)sessionData.get(SessionKeys.APP_CODE)); - Logger.debug("token: " + token); + if (Logger.isDebugEnabled()) Logger.debug("username: " + (String)sessionData.get(SessionKeys.USERNAME)); + if (Logger.isDebugEnabled()) Logger.debug("password: " ); + if (Logger.isDebugEnabled()) Logger.debug("appcode: " + (String)sessionData.get(SessionKeys.APP_CODE)); + if (Logger.isDebugEnabled()) Logger.debug("token: " + token); return true; }else{ - Logger.debug("Session Token unknown"); + if (Logger.isDebugEnabled()) Logger.debug("Session Token unknown"); return false; } }else{ - Logger.debug("Session Token header is null"); + if (Logger.isDebugEnabled()) Logger.debug("Session Token header is null"); return false; } } diff --git a/app/com/baasbox/controllers/actions/filters/UserCredentialWrapFilter.java b/app/com/baasbox/controllers/actions/filters/UserCredentialWrapFilter.java index 4934bad3..778e5851 100644 --- a/app/com/baasbox/controllers/actions/filters/UserCredentialWrapFilter.java +++ b/app/com/baasbox/controllers/actions/filters/UserCredentialWrapFilter.java @@ -34,7 +34,7 @@ public class UserCredentialWrapFilter extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Result tempResult=null; Http.Context.current.set(ctx); String token=ctx.request().getHeader(SessionKeys.TOKEN.toString()); @@ -48,8 +48,8 @@ public Result call(Context ctx) throws Throwable { else tempResult=badRequest("Missing Session Token, Authorization info and even the AppCode"); }else if (!StringUtils.isEmpty(authHeader) && StringUtils.isEmpty(RequestHeaderHelper.getAppCode(ctx))) { - Logger.debug("There is basic auth header, but the appcode is missing"); - Logger.debug("Invalid App Code, AppCode is empty!"); + if (Logger.isDebugEnabled()) Logger.debug("There is basic auth header, but the appcode is missing"); + if (Logger.isDebugEnabled()) Logger.debug("Invalid App Code, AppCode is empty!"); tempResult= badRequest("Invalid App Code. AppCode is empty or not set"); } @@ -76,8 +76,8 @@ public Result call(Context ctx) throws Throwable { WrapResponse wr = new WrapResponse(); Result result=wr.wrap(ctx, tempResult); - Logger.debug(result.toString()); - Logger.trace("Method End"); + if (Logger.isDebugEnabled()) Logger.debug(result.toString()); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/UserOrAnonymousCredentialsFilter.java b/app/com/baasbox/controllers/actions/filters/UserOrAnonymousCredentialsFilter.java index fb1945b9..070e1f92 100644 --- a/app/com/baasbox/controllers/actions/filters/UserOrAnonymousCredentialsFilter.java +++ b/app/com/baasbox/controllers/actions/filters/UserOrAnonymousCredentialsFilter.java @@ -40,7 +40,7 @@ public class UserOrAnonymousCredentialsFilter extends Action.Simple { @Override public Result call(Context ctx) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Result tempResult = null; Http.Context.current.set(ctx); String token = ctx.request().getHeader(SessionKeys.TOKEN.toString()); @@ -69,8 +69,8 @@ public Result call(Context ctx) throws Throwable { if (!isCredentialOk) { if (!StringUtils.isEmpty(authHeader) && StringUtils.isEmpty(RequestHeaderHelper.getAppCode(ctx))) { - Logger.debug("There is basic auth header, but the appcode is missing"); - Logger.debug("Invalid App Code, AppCode is empty!"); + if (Logger.isDebugEnabled()) Logger.debug("There is basic auth header, but the appcode is missing"); + if (Logger.isDebugEnabled()) Logger.debug("Invalid App Code, AppCode is empty!"); tempResult = badRequest("Invalid App Code. AppCode is empty or not set"); } } @@ -108,8 +108,8 @@ public Result call(Context ctx) throws Throwable { WrapResponse wr = new WrapResponse(); Result result = wr.wrap(ctx, tempResult); - Logger.debug(result.toString()); - Logger.trace("Method End"); + if (Logger.isDebugEnabled()) Logger.debug(result.toString()); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } diff --git a/app/com/baasbox/controllers/actions/filters/WrapResponse.java b/app/com/baasbox/controllers/actions/filters/WrapResponse.java index f585223b..ce26ec0a 100644 --- a/app/com/baasbox/controllers/actions/filters/WrapResponse.java +++ b/app/com/baasbox/controllers/actions/filters/WrapResponse.java @@ -133,7 +133,7 @@ private Result onOk(int statusCode,RequestHeader request, String stringBody) thr } public Result wrap(Context ctx, Result result) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ctx.response().setHeader("Access-Control-Allow-Origin", "*"); ctx.response().setHeader("Access-Control-Allow-Headers", "X-Requested-With"); @@ -143,14 +143,14 @@ public Result wrap(Context ctx, Result result) throws Throwable { byte[] resultContent=null; if (BBConfiguration.getWrapResponse()){ - Logger.debug("Wrapping the response"); + if (Logger.isDebugEnabled()) Logger.debug("Wrapping the response"); final int statusCode = JavaResultExtractor.getStatus(result); - Logger.debug("Executed API: " + ctx.request() + " , return code " + statusCode); - Logger.debug("Result type:"+result.getWrappedResult().getClass().getName() + " Response Content-Type:" +ctx.response().getHeaders().get("Content-Type")); + if (Logger.isDebugEnabled()) Logger.debug("Executed API: " + ctx.request() + " , return code " + statusCode); + if (Logger.isDebugEnabled()) Logger.debug("Result type:"+result.getWrappedResult().getClass().getName() + " Response Content-Type:" +ctx.response().getHeaders().get("Content-Type")); if (ctx.response().getHeaders().get("Content-Type")!=null && !ctx.response().getHeaders().get("Content-Type").contains("json")){ - Logger.debug("The response is a file, no wrap will be applied"); + if (Logger.isDebugEnabled()) Logger.debug("The response is a file, no wrap will be applied"); return result; } @@ -160,7 +160,7 @@ public Result wrap(Context ctx, Result result) throws Throwable { final byte[] body = JavaResultExtractor.getBody(result); String stringBody = new String(body, "UTF-8"); - if (Logger.isTraceEnabled()) Logger.trace ("stringBody: " +stringBody); + if (Logger.isTraceEnabled()) if (Logger.isTraceEnabled()) Logger.trace ("stringBody: " +stringBody); if (statusCode>399){ //an error has occured switch (statusCode) { case 400: result =onBadRequest(ctx.request(),stringBody); @@ -185,13 +185,13 @@ public Result wrap(Context ctx, Result result) throws Throwable { if (Logger.isDebugEnabled()) Logger.debug("WrapperResponse:\n + result: \n" + result.toString() + "\n --> Body:\n" + new String(JavaResultExtractor.getBody(result),"UTF-8")); }catch (Throwable e){} }else{ //if (BBConfiguration.getWrapResponse()) - Logger.debug("The response will not be wrapped due configuration parameter"); + if (Logger.isDebugEnabled()) Logger.debug("The response will not be wrapped due configuration parameter"); try { if (Logger.isDebugEnabled()) Logger.debug("WrapperResponse:\n + result: \n" + result.toString() + "\n --> Body:\n" + new String(JavaResultExtractor.getBody(result),"UTF-8")); }catch (Throwable e){} if (Logger.isDebugEnabled()) Logger.debug("WrapperResponse:\n + result: \n" + result.toString() + "\n --> Body:\n" + new String(JavaResultExtractor.getBody(result),"UTF-8")); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; }//wrap diff --git a/app/com/baasbox/dao/CollectionDao.java b/app/com/baasbox/dao/CollectionDao.java index 7b614ca4..09ba46bc 100644 --- a/app/com/baasbox/dao/CollectionDao.java +++ b/app/com/baasbox/dao/CollectionDao.java @@ -57,7 +57,7 @@ public ODocument create(){ * @throws Throwable */ public ODocument create(String collectionName) throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); try { if (existsCollection(collectionName)) throw new CollectionAlreadyExistsException("Collection " + collectionName + " already exists"); }catch (SqlInjectionException e){ @@ -86,20 +86,20 @@ public ODocument create(String collectionName) throws Throwable { anonymousRole.addRule(ODatabaseSecurityResources.CLUSTER + "." + collectionName, ORole.PERMISSION_READ); PermissionsHelper.grantRead(doc, registeredRole); PermissionsHelper.grantRead(doc, anonymousRole); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return doc; }//getNewModelInstance(String collectionName) public boolean existsCollection(String collectionName) throws SqlInjectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); OIndex idx = db.getMetadata().getIndexManager().getIndex(COLLECTION_NAME_INDEX); OIdentifiable record = (OIdentifiable) idx.get( collectionName ); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return (record!=null) ; } public ODocument getByName(String collectionName) throws SqlInjectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); OIndex idx = db.getMetadata().getIndexManager().getIndex(COLLECTION_NAME_INDEX); OIdentifiable record = (OIdentifiable) idx.get( collectionName ); if (record==null) return null; @@ -149,7 +149,7 @@ public void delete(String name) throws Exception{ } catch (Exception e) { //rollback in case of error DbHelper.rollbackTransaction(); - Logger.debug ("An error occured deleting the collection " + name, e); + if (Logger.isDebugEnabled()) Logger.debug ("An error occured deleting the collection " + name, e); throw e; } }//delete diff --git a/app/com/baasbox/dao/DocumentDao.java b/app/com/baasbox/dao/DocumentDao.java index fc435a9e..a0e99b0a 100644 --- a/app/com/baasbox/dao/DocumentDao.java +++ b/app/com/baasbox/dao/DocumentDao.java @@ -51,10 +51,10 @@ public static DocumentDao getInstance(String collectionName) throws InvalidColle @Override public ODocument create() throws Throwable{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); DbHelper.requestTransaction(); ODocument doc = super.create(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return doc; }//getNewModelInstance diff --git a/app/com/baasbox/dao/GenericDao.java b/app/com/baasbox/dao/GenericDao.java index 32302438..b4e26b0f 100644 --- a/app/com/baasbox/dao/GenericDao.java +++ b/app/com/baasbox/dao/GenericDao.java @@ -52,9 +52,9 @@ public ODocument get(String rid) throws IllegalArgumentException{ public ODocument get(ORID rid) { ODatabaseRecordTx db =DbHelper.getConnection(); - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODocument doc=db.load(rid); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return doc; } diff --git a/app/com/baasbox/dao/NodeDao.java b/app/com/baasbox/dao/NodeDao.java index d55ec1d8..52211d1f 100644 --- a/app/com/baasbox/dao/NodeDao.java +++ b/app/com/baasbox/dao/NodeDao.java @@ -123,7 +123,7 @@ public List selectByQuery(String query) throws InvalidCriteriaExcepti } public ODocument create() throws Throwable { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); OGraphDatabase db = DbHelper.getOGraphDatabaseConnection(); try{ ODocument doc = new ODocument(this.MODEL_NAME); @@ -132,24 +132,24 @@ public ODocument create() throws Throwable { doc.field(FIELD_CREATION_DATE,new Date()); vertex.field(FIELD_TO_DOCUMENT_FIELD,doc); UUID token = UUID.randomUUID(); - Logger.debug("CreateUUID.onRecordBeforeCreate: " + doc.getIdentity() + " -->> " + token.toString()); + if (Logger.isDebugEnabled()) Logger.debug("CreateUUID.onRecordBeforeCreate: " + doc.getIdentity() + " -->> " + token.toString()); doc.field(BaasBoxPrivateFields.ID.toString(),token.toString()); doc.field(BaasBoxPrivateFields.AUTHOR.toString(),db.getUser().getName()); return doc; }catch (Throwable e){ throw e; }finally{ - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } } protected void save(ODocument document) throws InvalidModelException { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); checkModelDocument(document); document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } @@ -167,7 +167,7 @@ public void update(ODocument originalDocument, ODocument documentToMerge) throws public List get(QueryParams criteria) throws SqlInjectionException, InvalidCriteriaException { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); List result = null; OCommandRequest command = DbHelper.selectCommandBuilder(MODEL_NAME, false, criteria); try{ @@ -184,13 +184,13 @@ public List get(QueryParams criteria) throws SqlInjectionException, I }catch (IndexOutOfBoundsException e){ throw new InvalidCriteriaException("Invalid criteria. Please check your query, the syntax and the parameters",e); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return result; } public ODocument get(ORID rid) throws InvalidModelException, DocumentNotFoundException { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Object doc=db.load(rid); if (doc==null) throw new DocumentNotFoundException(); if (!(doc instanceof ODocument)) throw new IllegalArgumentException(rid +" is a rid not referencing a valid Document"); @@ -200,18 +200,18 @@ public ODocument get(ORID rid) throws InvalidModelException, DocumentNotFoundExc //the rid may reference a ORecordBytes which is not a ODocument throw new InvalidModelException("the rid " + rid + " is not valid belong to the collection " + this.MODEL_NAME); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return (ODocument)doc; } public ODocument get(String rid) throws InvalidModelException, ODatabaseException, DocumentNotFoundException { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Object orid=OSQLHelper.parseValue(rid, null); if ((orid==null) || !(orid instanceof ORecordId) || (orid.toString().equals(OSQLHelper.VALUE_NOT_PARSED))) throw new IllegalArgumentException(rid +" is not a valid rid"); Object odoc=get((ORecordId)orid); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return (ODocument)odoc; } @@ -262,7 +262,7 @@ public long getCount(){ } public long getCount(QueryParams criteria) throws SqlInjectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); List result = null; OCommandRequest command = DbHelper.selectCommandBuilder(MODEL_NAME, true, criteria); try{ @@ -275,20 +275,20 @@ public long getCount(QueryParams criteria) throws SqlInjectionException{ }catch (OCommandSQLParsingException e){ throw new InvalidCriteriaException("Invalid criteria. Please check the syntax of you 'where' and/or 'orderBy' clauses. Hint: if you used < or > operators, put spaces before and after them",e); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return ((Long)result.get(0).field("count")).longValue(); } public void delete(String rid) throws Throwable{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODocument doc = get(rid); delete(doc.getIdentity()); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } public void delete(ORID rid) throws Throwable{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); OGraphDatabase db = DbHelper.getOGraphDatabaseConnection(); //retrieve the vertex associated to this node try{ @@ -301,7 +301,7 @@ public void delete(ORID rid) throws Throwable{ DbHelper.rollbackTransaction(); throw e; } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } diff --git a/app/com/baasbox/dao/PermissionsHelper.java b/app/com/baasbox/dao/PermissionsHelper.java index e27969cf..dcb1ccb6 100644 --- a/app/com/baasbox/dao/PermissionsHelper.java +++ b/app/com/baasbox/dao/PermissionsHelper.java @@ -54,29 +54,29 @@ public static ODocument grantRead(ODocument document,OUser user){ } public static ODocument changeOwner(ODocument document,OUser user){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Set set = new HashSet(); set.add( user.getDocument().getIdentity() ); document.field( Permissions.ALLOW.toString(), set, OType.LINKSET ); document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument changeOwner(ODocument document,OIdentifiable user){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Set set = new HashSet(); set.add( user ); document.field( Permissions.ALLOW.toString(), set, OType.LINKSET ); document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } /* Delayed due an OrientDb bug, see patch below public static ODocument grant(ODocument document, Permissions permission, ORole role) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (role==null){ Logger.warn("role is null! Grant command skipped"); return document; @@ -84,26 +84,26 @@ public static ODocument grant(ODocument document, Permissions permission, ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().allowRole(document, permission.toString(), role.getName()); document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument grant(ODocument document, Permissions permission, OUser user) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (user==null){ Logger.warn("user is null! Grant command skipped"); return document; } ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().allowUser(document, permission.toString(), user.getName()); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument revoke(ODocument document, Permissions permission, ORole role) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (role==null){ Logger.warn("role is null! Revoke command skipped"); return document; @@ -111,27 +111,27 @@ public static ODocument revoke(ODocument document, Permissions permission, ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().disallowRole(document, permission.toString(), role.getName()); document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument revoke(ODocument document, Permissions permission, OUser user) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (user==null){ Logger.warn("user is null! Revoke command skipped"); return document; } ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().disallowUser(document, permission.toString(), user.getName()); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } */ public static ODocument grant(ODocument document, Permissions permission, ORole role) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (role==null){ Logger.warn("role is null! Grant command skipped"); return document; @@ -145,13 +145,13 @@ public static ODocument grant(ODocument document, Permissions permission, document.field( permission.toString(), set, OType.LINKSET ); */ document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument grant(ODocument document, Permissions permission, OUser user) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().allowIdentity(document, permission.toString(), user.getDocument().getIdentity()); /* @@ -161,13 +161,13 @@ public static ODocument grant(ODocument document, Permissions permission, document.field( permission.toString(), set, OType.LINKSET ); */ document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument revoke(ODocument document, Permissions permission, ORole role) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().disallowIdentity(document, permission.toString(), role.getDocument().getIdentity()); /* @@ -177,13 +177,13 @@ public static ODocument revoke(ODocument document, Permissions permission, document.field( permission.toString(), set, OType.LINKSET ); */ document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } public static ODocument revoke(ODocument document, Permissions permission, OUser user) { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODatabaseRecordTx db = DbHelper.getConnection(); db.getMetadata().getSecurity().disallowIdentity(document, permission.toString(), user.getDocument().getIdentity()); /* @@ -193,7 +193,7 @@ public static ODocument revoke(ODocument document, Permissions permission, document.field( permission.toString(), set, OType.LINKSET ); */ document.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return document; } } diff --git a/app/com/baasbox/dao/UserDao.java b/app/com/baasbox/dao/UserDao.java index 76aee0c8..91e581b7 100644 --- a/app/com/baasbox/dao/UserDao.java +++ b/app/com/baasbox/dao/UserDao.java @@ -130,7 +130,7 @@ public ODocument getBySocialUserId(UserInfo ui) throws SqlInjectionException{ where.append(UserDao.SOCIAL_LOGIN_INFO).append("[").append(ui.getFrom()).append("]").append(".id").append(" = ?"); QueryParams criteria = QueryParams.getInstance().where(where.toString()).params(new String [] {ui.getId()}); List resultList= super.get(criteria); - Logger.debug("Found "+resultList.size() +" elements for given tokens"); + if (Logger.isDebugEnabled()) Logger.debug("Found "+resultList.size() +" elements for given tokens"); if (resultList!=null && resultList.size()>0) result = resultList.get(0); return result; diff --git a/app/com/baasbox/db/DbHelper.java b/app/com/baasbox/db/DbHelper.java index 88a8ec81..d5e657a4 100644 --- a/app/com/baasbox/db/DbHelper.java +++ b/app/com/baasbox/db/DbHelper.java @@ -16,7 +16,7 @@ */ package com.baasbox.db; -import static play.Logger.debug; + import java.io.FileInputStream; import java.io.IOException; @@ -105,7 +105,7 @@ public static boolean isInTransaction(){ public static void requestTransaction(){ ODatabaseRecordTx db = getConnection(); if (!isInTransaction()){ - Logger.trace("Begin transaction"); + if (Logger.isTraceEnabled()) Logger.trace("Begin transaction"); //db.begin(); } } @@ -113,7 +113,7 @@ public static void requestTransaction(){ public static void commitTransaction(){ ODatabaseRecordTx db = getConnection(); if (isInTransaction()){ - Logger.trace("Commit transaction"); + if (Logger.isTraceEnabled()) Logger.trace("Commit transaction"); //db.commit(); } } @@ -121,7 +121,7 @@ public static void commitTransaction(){ public static void rollbackTransaction(){ ODatabaseRecordTx db = getConnection(); if (isInTransaction()){ - Logger.trace("Rollback transaction"); + if (Logger.isTraceEnabled()) Logger.trace("Rollback transaction"); //db.rollback(); } } @@ -145,7 +145,7 @@ public static String selectQueryBuilder (String from, boolean count, QueryParams " limit " + criteria.getRecordPerPage(); } - Logger.debug("queryBuilder: " + ret); + if (Logger.isDebugEnabled()) Logger.debug("queryBuilder: " + ret); return ret; } @@ -163,9 +163,9 @@ public static OCommandRequest selectCommandBuilder(String from, boolean count, Q selectQueryBuilder(from, count, criteria) )); if (!command.isIdempotent()) throw new SqlInjectionException(); - Logger.debug("commandBuilder: "); - Logger.debug(" " + criteria.toString()); - Logger.debug(" " + command.toString()); + if (Logger.isDebugEnabled()) Logger.debug("commandBuilder: "); + if (Logger.isDebugEnabled()) Logger.debug(" " + criteria.toString()); + if (Logger.isDebugEnabled()) Logger.debug(" " + command.toString()); return command; } @@ -268,7 +268,7 @@ public static ODatabaseRecordTx open(String appcode, String username,String pass throw new ShuttingDownDBException(); } String databaseName=BBConfiguration.getDBDir(); - Logger.debug("opening connection on db: " + databaseName + " for " + username); + if (Logger.isDebugEnabled()) Logger.debug("opening connection on db: " + databaseName + " for " + username); new ODatabaseDocumentTx("plocal:" + BBConfiguration.getDBDir()).open(username,password); HooksManager.registerAll(getConnection()); @@ -299,11 +299,11 @@ public static ODatabaseRecordTx reconnectAsAuthenticatedUser (){ } public static void close(ODatabaseRecordTx db) { - Logger.debug("closing connection"); + if (Logger.isDebugEnabled()) Logger.debug("closing connection"); if (db!=null && !db.isClosed()){ //HooksManager.unregisteredAll(db); db.close(); - }else Logger.debug("connection already close or null"); + }else if (Logger.isDebugEnabled()) Logger.debug("connection already close or null"); } public static ODatabaseRecordTx getConnection(){ @@ -327,20 +327,20 @@ public static boolean isConnectedLikeBaasBox(){ } public static void createDefaultRoles() throws RoleNotFoundException, RoleAlreadyExistsException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); RoleService.createInternalRoles(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } public static void createDefaultUsers() throws Exception{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); UserService.createDefaultUsers(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } public static void updateDefaultUsers() throws Exception{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODatabaseRecordTx db = DbHelper.getConnection(); OUser user=db.getMetadata().getSecurity().getUser(BBConfiguration.getBaasBoxUsername()); user.setPassword(BBConfiguration.getBaasBoxPassword()); @@ -350,14 +350,14 @@ public static void updateDefaultUsers() throws Exception{ user.setPassword(BBConfiguration.getBaasBoxAdminPassword()); user.save(); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } @Deprecated public static void dropOrientDefault(){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); //nothing to do here - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } public static void populateDB(ODatabaseRecordTx db) throws IOException{ @@ -370,7 +370,7 @@ public static void populateDB(ODatabaseRecordTx db) throws IOException{ is.close(); for (String line:script){ - Logger.debug(line); + if (Logger.isDebugEnabled()) Logger.debug(line); if (!line.startsWith("--") && !line.trim().isEmpty()){ //skip comments dbg.command(new OCommandSQL(line.replace(';', ' '))).execute(); } @@ -428,9 +428,9 @@ public static void populateConfiguration (ODatabaseRecordTx db) throws IOExcepti public static void setupDb(ODatabaseRecordTx db) throws Exception{ - debug("Creating default roles..."); + Logger.info("Creating default roles..."); DbHelper.createDefaultRoles(); - debug("Creating default users..."); + Logger.info("Creating default users..."); DbHelper.dropOrientDefault(); populateDB(db); createDefaultUsers(); diff --git a/app/com/baasbox/db/Evolution_0_7_3.java b/app/com/baasbox/db/Evolution_0_7_3.java index 0a341b4e..02fddd87 100644 --- a/app/com/baasbox/db/Evolution_0_7_3.java +++ b/app/com/baasbox/db/Evolution_0_7_3.java @@ -65,7 +65,7 @@ private void changeDefaultDateTimeFormat(ODatabaseRecordTx db) { String[] script=new String[]{ "alter database DATETIMEFORMAT yyyy-MM-dd'T'HH:mm:ss.sssZ;"}; for (String line:script){ - Logger.debug(line); + if (Logger.isDebugEnabled()) Logger.debug(line); if (!line.startsWith("--") && !line.trim().isEmpty()){ //skip comments db.command(new OCommandSQL(line.replace(';', ' '))).execute(); } @@ -93,7 +93,7 @@ private void fileClassCreation(ODatabaseRecordTx db) { "create property _BB_File_Content.content String;", "create index _BB_File_Content.content.key FULLTEXT_HASH_INDEX;"}; for (String line:script){ - Logger.debug(line); + if (Logger.isDebugEnabled()) Logger.debug(line); if (!line.startsWith("--") && !line.trim().isEmpty()){ //skip comments db.command(new OCommandSQL(line.replace(';', ' '))).execute(); } diff --git a/app/com/baasbox/db/hook/Audit.java b/app/com/baasbox/db/hook/Audit.java index 8a1bb0e3..3f13fa92 100644 --- a/app/com/baasbox/db/hook/Audit.java +++ b/app/com/baasbox/db/hook/Audit.java @@ -39,7 +39,7 @@ protected Audit() { @Override public com.orientechnologies.orient.core.hook.ORecordHook.RESULT onRecordBeforeCreate(ORecord iRecord){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (iRecord instanceof ODocument){ ODocument doc = (ODocument)iRecord; if ( @@ -48,7 +48,7 @@ public com.orientechnologies.orient.core.hook.ORecordHook.RESULT onRecordBeforeC ( doc.field("type")==null ) ){ if(!doc.isEmbedded() && doc.getClassName()!=null && doc.getSchemaClass().isSubClassOf(NodeDao.CLASS_NODE_NAME)){ - Logger.debug(" AuditHook.onRecordBeforeCreate: creation of audit fields for document " + doc.getIdentity()); + if (Logger.isDebugEnabled()) Logger.debug(" AuditHook.onRecordBeforeCreate: creation of audit fields for document " + doc.getIdentity()); ODocument auditDoc = new ODocument(); Date data = new Date(); auditDoc.field("type",BBInternalConstants.FIELD_AUDIT); @@ -61,13 +61,13 @@ public com.orientechnologies.orient.core.hook.ORecordHook.RESULT onRecordBeforeC }//doc.getClassName() } }//iRecord instanceof ODocument - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return RESULT.RECORD_NOT_CHANGED; }//onRecordBeforeCreate @Override public com.orientechnologies.orient.core.hook.ORecordHook.RESULT onRecordBeforeUpdate (ORecord iRecord){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (iRecord instanceof ODocument){ ODocument doc = (ODocument)iRecord; if ( @@ -76,7 +76,7 @@ public com.orientechnologies.orient.core.hook.ORecordHook.RESULT onRecordBeforeU ( doc.field("type")==null ) ){ if(!doc.isEmbedded() && doc.getClassName()!=null && doc.getSchemaClass().isSubClassOf(NodeDao.CLASS_NODE_NAME)){ - Logger.debug(" AuditHook.onRecordBeforeUpdate: update of audit fields for ORecord: " + iRecord.getIdentity()); + if (Logger.isDebugEnabled()) Logger.debug(" AuditHook.onRecordBeforeUpdate: update of audit fields for ORecord: " + iRecord.getIdentity()); ODocument auditDoc = doc.field(BBInternalConstants.FIELD_AUDIT); if (auditDoc==null) auditDoc = new ODocument(); Date data = new Date(); @@ -87,7 +87,7 @@ public com.orientechnologies.orient.core.hook.ORecordHook.RESULT onRecordBeforeU } } } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return RESULT.RECORD_NOT_CHANGED; }//onRecordBeforeUpdate diff --git a/app/com/baasbox/db/hook/HooksManager.java b/app/com/baasbox/db/hook/HooksManager.java index cd2f3f8d..174b2b23 100644 --- a/app/com/baasbox/db/hook/HooksManager.java +++ b/app/com/baasbox/db/hook/HooksManager.java @@ -31,45 +31,45 @@ public class HooksManager { public static void registerAll(ODatabaseRecordTx db){ - Logger.trace("Method Start"); - Logger.debug("Registering hooks..."); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); + if (Logger.isDebugEnabled()) Logger.debug("Registering hooks..."); //we have to check if the hooks have been already registered since the connections could be reused due to pool Set hooks = db.getHooks(); Iterator it =hooks.iterator(); boolean register=true; while (it.hasNext()){ if (it.next() instanceof BaasBoxHook) { - Logger.debug("BaasBox hooks already registerd for this connection"); + if (Logger.isDebugEnabled()) Logger.debug("BaasBox hooks already registerd for this connection"); register=false; break; } } if (register){ - Logger.debug("Registering BaasBox hooks... start"); + if (Logger.isDebugEnabled()) Logger.debug("Registering BaasBox hooks... start"); db.registerHook(Audit.getIstance(),HOOK_POSITION.REGULAR); - Logger.debug("Registering BaasBox hooks... done"); + if (Logger.isDebugEnabled()) Logger.debug("Registering BaasBox hooks... done"); } - Logger.debug("Hooks: "+ db.getHooks()); - Logger.trace("Method End"); + if (Logger.isDebugEnabled()) Logger.debug("Hooks: "+ db.getHooks()); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } public static void unregisteredAll(ODatabaseRecordTx db){ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); - Logger.debug("unregistering hooks..."); + if (Logger.isDebugEnabled()) Logger.debug("unregistering hooks..."); Set hooks = db.getHooks(); List hs = IteratorUtils.toList(hooks.iterator()); Iterator it =hs.iterator(); while (it.hasNext()){ ORecordHook h = it.next(); if (h instanceof BaasBoxHook) { - Logger.debug("Removing "+ ((BaasBoxHook) h).getHookName() + " hook"); + if (Logger.isDebugEnabled()) Logger.debug("Removing "+ ((BaasBoxHook) h).getHookName() + " hook"); db.unregisterHook(h); } } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } } diff --git a/app/com/baasbox/security/SessionTokenProvider.java b/app/com/baasbox/security/SessionTokenProvider.java index 1af4dfde..218ba3e2 100644 --- a/app/com/baasbox/security/SessionTokenProvider.java +++ b/app/com/baasbox/security/SessionTokenProvider.java @@ -62,7 +62,7 @@ public SessionTokenProvider(){ public void setTimeout(long timeoutInMilliseconds){ this.expiresInMilliseconds=timeoutInMilliseconds; - Logger.debug("New session timeout: " + timeoutInMilliseconds + " ms"); + if (Logger.isDebugEnabled()) Logger.debug("New session timeout: " + timeoutInMilliseconds + " ms"); } //setTimeout @Override @@ -96,7 +96,7 @@ public void setTimeout(long timeoutInMilliseconds){ @Override public void removeSession(String token) { - Logger.debug("SessionTokenProvider: " + token + " removed"); + if (Logger.isDebugEnabled()) Logger.debug("SessionTokenProvider: " + token + " removed"); sessions.remove(token); } diff --git a/app/com/baasbox/service/push/PushService.java b/app/com/baasbox/service/push/PushService.java index 96c658c6..1953b39e 100644 --- a/app/com/baasbox/service/push/PushService.java +++ b/app/com/baasbox/service/push/PushService.java @@ -46,25 +46,25 @@ private ImmutableMap getPushParameters(){ } public void send(String message, String username) throws PushNotInitializedException, UserNotFoundException, SqlInjectionException, InvalidRequestException, IOException, UnknownHostException{ - Logger.debug("Try to send a message (" + message + ") to " + username); + if (Logger.isDebugEnabled()) Logger.debug("Try to send a message (" + message + ") to " + username); UserDao udao = UserDao.getInstance(); ODocument user = udao.getByUserName(username); if (user==null) { - Logger.debug("User " + username + " does not exist"); + if (Logger.isDebugEnabled()) Logger.debug("User " + username + " does not exist"); throw new UserNotFoundException("User " + username + " does not exist"); } ODocument userSystemProperties = user.field(UserDao.ATTRIBUTES_SYSTEM); - Logger.debug("userSystemProperties: " + userSystemProperties); + if (Logger.isDebugEnabled()) Logger.debug("userSystemProperties: " + userSystemProperties); List loginInfos=userSystemProperties.field(UserDao.USER_LOGIN_INFO); - Logger.debug("Sending to " + loginInfos.size() + " devices"); + if (Logger.isDebugEnabled()) Logger.debug("Sending to " + loginInfos.size() + " devices"); for(ODocument loginInfo : loginInfos){ String deviceId=loginInfo.field(UserDao.USER_DEVICE_ID); String vendor=loginInfo.field(UserDao.USER_DEVICE_OS); - Logger.debug ("deviceId: " + deviceId); - Logger.debug ("vendor: " + vendor); + if (Logger.isDebugEnabled()) Logger.debug ("deviceId: " + deviceId); + if (Logger.isDebugEnabled()) Logger.debug ("vendor: " + vendor); if(!StringUtils.isEmpty(vendor) && !StringUtils.isEmpty(deviceId)){ VendorOS vos = VendorOS.getVendorOs(vendor); - Logger.debug("vos: " + vos); + if (Logger.isDebugEnabled()) Logger.debug("vos: " + vos); if (vos!=null){ IPushServer pushServer = Factory.getIstance(vos); pushServer.setConfiguration(getPushParameters()); diff --git a/app/com/baasbox/service/push/providers/APNServer.java b/app/com/baasbox/service/push/providers/APNServer.java index abf935db..034fcd86 100644 --- a/app/com/baasbox/service/push/providers/APNServer.java +++ b/app/com/baasbox/service/push/providers/APNServer.java @@ -39,7 +39,7 @@ public int INCREMENT_ID() { @Override public void send(String message, String deviceid) throws PushNotInitializedException{ - Logger.debug("APN Push message: "+message+" to the device "+deviceid); + if (Logger.isDebugEnabled()) Logger.debug("APN Push message: "+message+" to the device "+deviceid); if (!isInit) throw new PushNotInitializedException("Configuration not initialized"); ApnsService service = null; try{ diff --git a/app/com/baasbox/service/push/providers/GCMServer.java b/app/com/baasbox/service/push/providers/GCMServer.java index 12cfac4f..9f927539 100644 --- a/app/com/baasbox/service/push/providers/GCMServer.java +++ b/app/com/baasbox/service/push/providers/GCMServer.java @@ -26,7 +26,7 @@ public class GCMServer extends Controller implements IPushServer { public void send(String message, String deviceid) throws PushNotInitializedException, InvalidRequestException, UnknownHostException,IOException { - Logger.debug("GCM Push message: " + message + " to the device " + if (Logger.isDebugEnabled()) Logger.debug("GCM Push message: " + message + " to the device " + deviceid); if (!isInit) throw new PushNotInitializedException( diff --git a/app/com/baasbox/service/sociallogin/SocialLoginService.java b/app/com/baasbox/service/sociallogin/SocialLoginService.java index 990545f0..2b28393f 100644 --- a/app/com/baasbox/service/sociallogin/SocialLoginService.java +++ b/app/com/baasbox/service/sociallogin/SocialLoginService.java @@ -77,7 +77,7 @@ public String getAuthorizationURL(Session s){ if(this.needToken()){ t = this.service.getRequestToken(); if(this.socialNetwork.equals("twitter")){ - Logger.debug("setting token"); + if (Logger.isDebugEnabled()) Logger.debug("setting token"); s.put("twitter.token",t.getToken()); s.put("twitter.secret",t.getSecret()); } diff --git a/app/com/baasbox/service/sociallogin/TwitterLoginService.java b/app/com/baasbox/service/sociallogin/TwitterLoginService.java index 7ae53ed0..45dc3bfd 100644 --- a/app/com/baasbox/service/sociallogin/TwitterLoginService.java +++ b/app/com/baasbox/service/sociallogin/TwitterLoginService.java @@ -55,7 +55,7 @@ public String getVerifierFromRequest(Request r) { @Override public Token getAccessTokenFromRequest(Request r,Session s) { - Logger.debug(Json.stringify(Json.toJson(s.keySet()))); + if (Logger.isDebugEnabled()) Logger.debug(Json.stringify(Json.toJson(s.keySet()))); if(s.get("twitter.token")!=null && s.get("twitter.secret")!=null){ String token = s.get("twitter.token"); String secret = s.get("twitter.secret"); diff --git a/app/com/baasbox/service/storage/StatisticsService.java b/app/com/baasbox/service/storage/StatisticsService.java index afa041b6..56e985d0 100644 --- a/app/com/baasbox/service/storage/StatisticsService.java +++ b/app/com/baasbox/service/storage/StatisticsService.java @@ -52,7 +52,7 @@ public class StatisticsService { public static ImmutableMap data() throws SqlInjectionException, InvalidCollectionException{ - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); UserDao userDao = UserDao.getInstance(); CollectionDao collDao = CollectionDao.getInstance(); AssetDao assetDao = AssetDao.getInstance(); @@ -89,13 +89,13 @@ public static ImmutableMap data() throws SqlInjectionException, InvalidCollectio "collections_details", collMap, "assets",assetsCount ); - Logger.debug(response.toString()); - Logger.trace("Method End"); + if (Logger.isDebugEnabled()) Logger.debug(response.toString()); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return response; } public static String dbConfiguration() { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); OGlobalConfiguration.dumpConfiguration(ps); @@ -105,12 +105,12 @@ public static String dbConfiguration() { } catch (UnsupportedEncodingException e) { content=baos.toString(); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return content; } public static ImmutableMap db() { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ODatabaseRecordTx db = DbHelper.getConnection(); HashMap dbProp= new HashMap(); dbProp.put("version", OConstants.getVersion()); @@ -127,12 +127,12 @@ public static ImmutableMap db() { "configuration", dbConfiguration(), "physical_size",FileUtils.sizeOfDirectory(new File (BBConfiguration.getDBDir())) ); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return response; } public static ImmutableMap os() { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ImmutableMap response=null; if (BBConfiguration.getStatisticsSystemOS()){ response = ImmutableMap.of( @@ -149,24 +149,24 @@ public static ImmutableMap os() { "processors", 0 ); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return response; } public static ImmutableMap java() { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ImmutableMap response = ImmutableMap.of( "java_class_version", System.getProperty("java.class.version"), "java_vendor", System.getProperty("java.vendor"), "java_vendor_url", System.getProperty("java.vendor.url"), "java_version", System.getProperty("java.version") ); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return response; } public static ImmutableMap memory() { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); ImmutableMap response=null; if (BBConfiguration.getStatisticsSystemMemory()){ @@ -189,7 +189,7 @@ public static ImmutableMap memory() { ); } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return response; } diff --git a/app/com/baasbox/service/user/RoleService.java b/app/com/baasbox/service/user/RoleService.java index ee1f9f4b..b4af915a 100644 --- a/app/com/baasbox/service/user/RoleService.java +++ b/app/com/baasbox/service/user/RoleService.java @@ -58,7 +58,7 @@ public static void createRole(String name, String inheritedRole, String descript public static void createInternalRoles(){ for (DefaultRoles r : DefaultRoles.values()){ ORole newRole; - Logger.debug("creating " + r.toString() + "..."); + if (Logger.isDebugEnabled()) Logger.debug("creating " + r.toString() + "..."); if (!r.isOrientRole()){ //creates the new baasbox role newRole = RoleDao.createRole(r.toString(), r.getInheritsFrom()); }else{ //retrieve the existing OrientDB role diff --git a/app/com/baasbox/service/user/UserService.java b/app/com/baasbox/service/user/UserService.java index 4d2f27c8..afe8484e 100644 --- a/app/com/baasbox/service/user/UserService.java +++ b/app/com/baasbox/service/user/UserService.java @@ -396,7 +396,7 @@ public static void changePassword(String username, String newPassword) throws Sq UserDao udao=UserDao.getInstance(); ODocument user = udao.getByUserName(username); if(user==null){ - Logger.debug("User " + username + " does not exist"); + if (Logger.isDebugEnabled()) Logger.debug("User " + username + " does not exist"); throw new UserNotFoundException("User " + username + " does not exist"); } db.getMetadata().getSecurity().getUser(username).setPassword(newPassword).save(); @@ -521,7 +521,7 @@ public static void removeSocialLoginTokens(ODocument user , String socialNetwork user.field(UserDao.ATTRIBUTES_SYSTEM,systemProps); systemProps.save(); user.save(); - Logger.debug("saved tokens for user "); + if (Logger.isDebugEnabled()) Logger.debug("saved tokens for user "); DbHelper.commitTransaction(); } }catch(Exception e){ @@ -547,7 +547,7 @@ public static void addSocialLoginTokens(ODocument user , UserInfo userInfo) thro user.field(UserDao.ATTRIBUTES_SYSTEM,systemProps); systemProps.save(); user.save(); - Logger.debug("saved tokens for user "); + if (Logger.isDebugEnabled()) Logger.debug("saved tokens for user "); DbHelper.commitTransaction(); }catch(Exception e){ diff --git a/app/com/baasbox/util/QueryParams.java b/app/com/baasbox/util/QueryParams.java index 37eb3ef0..5df76d48 100644 --- a/app/com/baasbox/util/QueryParams.java +++ b/app/com/baasbox/util/QueryParams.java @@ -42,20 +42,20 @@ public class QueryParams implements IQueryParametersKeys{ protected QueryParams(String where, Integer page, Integer recordPerPage, String orderBy, Integer depth, String[] params) { super(); - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (where!=null) this.where = where; if (page!=null) this.page = page; if (recordPerPage!=null) this.recordPerPage = recordPerPage; if (orderBy!=null) this.orderBy = orderBy; if (depth!=null) this.depth = depth; if (params!=null) this.params=params; - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } protected QueryParams(String where, Integer page, Integer recordPerPage, String orderBy, Integer depth, String param) { super(); - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); if (where!=null) this.where = where; if (page!=null) this.page = page; if (recordPerPage!=null) this.recordPerPage = recordPerPage; @@ -65,7 +65,7 @@ protected QueryParams(String where, Integer page, Integer recordPerPage, String[] params = {param}; this.params= params ; } - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); } public QueryParams(String fields, String where, Integer page, @@ -225,7 +225,7 @@ public static QueryParams getParamsFromQueryString(play.mvc.Http.RequestHeader h String groupByFromQS=null; String depthFromQS=null; - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); Map queryString = header.queryString(); if (queryString.get(IQueryParametersKeys.FIELDS)!=null) fieldsFromQS=queryString.get(IQueryParametersKeys.FIELDS)[0]; @@ -267,7 +267,7 @@ public static QueryParams getParamsFromQueryString(play.mvc.Http.RequestHeader h QueryParams qryp = new QueryParams(fields,groupBy,where, page, recordPerPage, orderBy, depth,params); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return qryp; } diff --git a/app/com/baasbox/util/Util.java b/app/com/baasbox/util/Util.java index 8af2f100..5fe33936 100644 --- a/app/com/baasbox/util/Util.java +++ b/app/com/baasbox/util/Util.java @@ -38,7 +38,7 @@ public class Util { */ /* public static String listToJSON(Collection iRecords,String fetchPlan) throws IOException { - Logger.trace("Method Start"); + if (Logger.isTraceEnabled()) Logger.trace("Method Start"); final StringWriter buffer = new StringWriter(); final OJSONWriter json = new OJSONWriter(buffer); json.beginCollection(0, false, null); @@ -61,7 +61,7 @@ public static String listToJSON(Collection iRecords,Str } } json.endCollection(0, false); - Logger.trace("Method End"); + if (Logger.isTraceEnabled()) Logger.trace("Method End"); return buffer.toString(); }//listToJSON */ @@ -79,7 +79,7 @@ public static boolean validateEmail(final String hex) { public static void createZipFile(String path,File...files) { - Logger.debug("Zipping into:"+path); + if (Logger.isDebugEnabled()) Logger.debug("Zipping into:"+path); ZipOutputStream zip = null; FileOutputStream dest = null; try{ diff --git a/test/AdminImportTest.java b/test/AdminImportTest.java index 50d84513..900b229c 100644 --- a/test/AdminImportTest.java +++ b/test/AdminImportTest.java @@ -90,7 +90,7 @@ public void testPostImport() throws Exception { public void invoke(TestBrowser browser) { - Logger.debug("Using zip file:"+correctZipFile.getAbsolutePath()); + if (Logger.isDebugEnabled()) Logger.debug("Using zip file:"+correctZipFile.getAbsolutePath()); setHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE); setHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC); setMultipartFormData(); diff --git a/test/AdminUserChangePasswordTest.java b/test/AdminUserChangePasswordTest.java index aad1ec6f..ea0b7688 100644 --- a/test/AdminUserChangePasswordTest.java +++ b/test/AdminUserChangePasswordTest.java @@ -74,8 +74,8 @@ public void run() request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC); request = request.withJsonBody(getPayload("/adminUserChangePasswordPayload.json"), getMethod()); Result result = routeAndCall(request); - Logger.debug("testRouteChangePassword request: " + request.getWrappedRequest().headers()); - Logger.debug("testRouteChangePassword result: " + contentAsString(result)); + if (Logger.isDebugEnabled()) Logger.debug("testRouteChangePassword request: " + request.getWrappedRequest().headers()); + if (Logger.isDebugEnabled()) Logger.debug("testRouteChangePassword result: " + contentAsString(result)); assertRoute(result, "testRouteChangePassword 1", Status.OK, null, false); continueOnFail(true); diff --git a/test/UserChangePasswordTest.java b/test/UserChangePasswordTest.java index 44909526..115be37d 100644 --- a/test/UserChangePasswordTest.java +++ b/test/UserChangePasswordTest.java @@ -85,8 +85,8 @@ public void run() request = request.withHeader(TestConfig.KEY_AUTH, sAuthEnc); request = request.withJsonBody(getPayload("/userChangePasswordPayload.json"), getMethod()); Result result = routeAndCall(request); - Logger.debug("testRouteChangePassword request: " + request.getWrappedRequest().headers()); - Logger.debug("testRouteChangePassword result: " + contentAsString(result)); + if (Logger.isDebugEnabled()) Logger.debug("testRouteChangePassword request: " + request.getWrappedRequest().headers()); + if (Logger.isDebugEnabled()) Logger.debug("testRouteChangePassword result: " + contentAsString(result)); assertRoute(result, "testRouteChangePassword", Status.OK, null, false); String sPwdChanged = getPayloadFieldValue("/userChangePasswordPayload.json", "new");