Skip to content

Commit

Permalink
Merge pull request #5 from mrsbluerose/Jira-TRIB-228
Browse files Browse the repository at this point in the history
Jira-TRIB-228: updates all occurrences of apache logger to lombok
  • Loading branch information
haxwell authored Dec 19, 2023
2 parents a4105df + c58c53a commit b4f7d5e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

import com.savvato.basemobileapp.constants.Constants;
import com.savvato.basemobileapp.services.UserPrincipalService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand All @@ -28,11 +27,10 @@
import io.jsonwebtoken.SignatureException;
import io.jsonwebtoken.UnsupportedJwtException;

@Slf4j
@Component
public class JwtTokenFilter extends OncePerRequestFilter {

private static final Log logger = LogFactory.getLog(JwtTokenFilter.class);

@Autowired
UserPrincipalService userPrincipalService;

Expand Down Expand Up @@ -79,15 +77,15 @@ private boolean validate(String token) {
Jwts.parser().setSigningKey(Constants.JWT_SECRET).parseClaimsJws(token);
return true;
} catch (SignatureException ex) {
logger.error("Invalid JWT signature - " + ex.getMessage());
log.error("Invalid JWT signature - " + ex.getMessage());
} catch (MalformedJwtException ex) {
logger.error("Invalid JWT token - " + ex.getMessage());
log.error("Invalid JWT token - " + ex.getMessage());
} catch (ExpiredJwtException ex) {
logger.error("Expired JWT token - " + ex.getMessage());
log.error("Expired JWT token - " + ex.getMessage());
} catch (UnsupportedJwtException ex) {
logger.error("Unsupported JWT token - " + ex.getMessage());
log.error("Unsupported JWT token - " + ex.getMessage());
} catch (IllegalArgumentException ex) {
logger.error("JWT claims string is empty - " + ex.getMessage());
log.error("JWT claims string is empty - " + ex.getMessage());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.savvato.basemobileapp.constants.ResourceTypeConstants;
import com.savvato.basemobileapp.services.PictureService;
import com.savvato.basemobileapp.services.StorageService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,11 +13,10 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@RestController
public class FileUploadController {

private static final Log logger = LogFactory.getLog(FileUploadController.class);

private final StorageService storageService;
private final PictureService pictureService;

Expand Down Expand Up @@ -60,10 +58,10 @@ public ResponseEntity<byte[]> serveFile(HttpServletRequest request, @PathVariabl
String filename = storageService.getDefaultFilename(resourceType, resourceId);
filename = pictureService.transformFilenameUsingSizeInfo(photoSize, filename);

logger.debug("^^^^^ About to call storageservice to load --> " + filename);
log.debug("^^^^^ About to call storageservice to load --> " + filename);
byte[] fileAsByteArray = storageService.loadAsByteArray(resourceType, filename);

logger.debug("^^^^^^ Back from storageservice call to load --> " + filename);
log.debug("^^^^^^ Back from storageservice call to load --> " + filename);
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(fileAsByteArray);
}

Expand All @@ -73,11 +71,11 @@ public String handleFileUpload(HttpServletRequest request, @PathVariable String

if (isValidResourceType(resourceType)) {
String filename = storageService.getDefaultFilename(resourceType, resourceId);
logger.debug("^^^^ About to call storage service to save --> " + filename);
log.debug("^^^^ About to call storage service to save --> " + filename);
storageService.store(resourceType, file, filename);

try {
logger.debug("^^^^ About to call pictureservice to write thumbnail --> " + filename);
log.debug("^^^^ About to call pictureservice to write thumbnail --> " + filename);
pictureService.writeThumbnailFromOriginal(resourceType, filename);
} catch (IOException ioe){
return "{\"msg\":\"error\"}";
Expand All @@ -86,7 +84,7 @@ public String handleFileUpload(HttpServletRequest request, @PathVariable String
return "{\"msg\":\"ok\"}";
}

logger.debug("^^^^^ COULD NOT do the HandleFileUpload!");
log.debug("^^^^^ COULD NOT do the HandleFileUpload!");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.savvato.basemobileapp.controllers;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import com.savvato.basemobileapp.controllers.dto.SMSChallengeRequest;
import com.savvato.basemobileapp.services.SMSChallengeCodeService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -14,11 +13,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Slf4j
@RestController
public class SMSChallengeCodeAPIController {

private static final Log logger = LogFactory.getLog(SMSChallengeCodeAPIController.class);

@Autowired
SMSChallengeCodeService smsccs;

Expand All @@ -30,7 +28,7 @@ public String sendSMSChallengeCode(@RequestBody @Valid SMSChallengeRequest req)
phoneNumber = "1" + phoneNumber;

String rtn = smsccs.sendSMSChallengeCodeToPhoneNumber(phoneNumber);
logger.debug("Sent challenge code to " + phoneNumber + ". " + rtn);
log.debug("Sent challenge code to " + phoneNumber + ". " + rtn);
return rtn;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.savvato.basemobileapp.services;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
Expand All @@ -14,15 +13,14 @@
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class CacheServiceImpl implements CacheService {

private static final Log logger = LogFactory.getLog(CacheServiceImpl.class);

HashMap<String, Cache<String, String>> mapCacheNameToCacheOfStringKtoStringV = new HashMap<>();

public CacheServiceImpl() {
logger.debug("Just created instance of CacheServiceImpl");
log.debug("Just created instance of CacheServiceImpl");
}

public void put(String cacheName, String key, String value) {
Expand All @@ -46,7 +44,7 @@ private Cache<String, String> getCache(String cacheName) {
return mapCacheNameToCacheOfStringKtoStringV.get(cacheName);
}

logger.debug("Cache " + cacheName + " was not found in the CacheService. Creating a new instance.");
log.debug("Cache " + cacheName + " was not found in the CacheService. Creating a new instance.");

CacheManager cm = CacheManagerBuilder.newCacheManagerBuilder()
.withCache(cacheName, CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.savvato.basemobileapp.services;

import com.savvato.basemobileapp.constants.Constants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Service;
Expand All @@ -15,11 +14,10 @@
import java.io.InputStream;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class PictureServiceImpl implements PictureService {

private static final Log logger = LogFactory.getLog(PictureServiceImpl.class);

@Autowired
ResourceTypeService resourceTypeService;

Expand All @@ -32,33 +30,33 @@ public void writeThumbnailFromOriginal(String resourceType, String filename) thr
long delay = 2;

while (!done && retryCount++ < 3) {
logger.debug("Sleeping.... " + delay);
log.debug("Sleeping.... " + delay);
try {
TimeUnit.SECONDS.sleep(delay);
} catch (InterruptedException ie) {

}
logger.debug("Woke up!");
log.debug("Woke up!");

delay *= 2;

try {
logger.debug("Just about to get the file " + dir + "/" + filename);
log.debug("Just about to get the file " + dir + "/" + filename);
InputStream is = new FileSystemResource(dir + "/" + filename).getInputStream();

BufferedImage originalImage = ImageIO.read(is);

if (originalImage != null) {

logger.debug("YES! Found the file.. doing the resize... " + dir + "/" + filename);
log.debug("YES! Found the file.. doing the resize... " + dir + "/" + filename);
BufferedImage resizedImage = resizeImage(originalImage, 250, 250);

File out = new File(dir + "/" + filename + "_thumbnail");
ImageIO.write(resizedImage, "jpg", out);

done = true;
} else {
logger.debug("nooo... the file wasn't there yet."+ dir + "/" + filename);
log.debug("nooo... the file wasn't there yet."+ dir + "/" + filename);
}
} catch (IOException ioe) {
throw new IOException("Expected the file " + dir + "/" + filename + " to be in place, but we got this exception instead!.", ioe);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.savvato.basemobileapp.services;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;


@Slf4j
@Service
public class SMSChallengeCodeServiceImpl implements SMSChallengeCodeService {

private static final Log logger = LogFactory.getLog(SMSChallengeCodeServiceImpl.class);

@Autowired
CacheService cache;

Expand All @@ -22,7 +19,7 @@ public class SMSChallengeCodeServiceImpl implements SMSChallengeCodeService {
public String sendSMSChallengeCodeToPhoneNumber(String phoneNumber) {
String rtn = "";
String challengeCode = getRandomStringOfNDigits(6);
logger.debug("SMS Challenge Code is:" + challengeCode);
log.debug("SMS Challenge Code is:" + challengeCode);
if (smss.sendSMS(phoneNumber, challengeCode + " <--- Your App Challenge Code")) {
cache.put("SMSChallengeCodesByPhoneNumber", phoneNumber, challengeCode);
rtn = challengeCode;
Expand All @@ -42,7 +39,7 @@ public boolean isAValidSMSChallengeCode(String phoneNumber, String code) {
String sentCode = cache.get("SMSChallengeCodesByPhoneNumber", phoneNumber);
rtn = sentCode != null && sentCode.equals(code);

logger.debug("isAValidSMSChallengeCode(), for ph# " + phoneNumber + " and user-supplied code " + code + " returns " + rtn);
log.debug("isAValidSMSChallengeCode(), for ph# " + phoneNumber + " and user-supplied code " + code + " returns " + rtn);

return rtn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import com.plivo.api.Plivo;
import com.plivo.api.models.message.Message;
import com.plivo.api.models.message.MessageCreateResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SMSTextMessageServiceImpl implements SMSTextMessageService {

private static final Log logger = LogFactory.getLog(SMSTextMessageServiceImpl.class);

@Autowired
CacheService cache;

Expand All @@ -30,13 +28,13 @@ public boolean sendSMS(String toPhoneNumber, String msg) {
rtn = true; // for use in testing. just act like we did it.
} else {
try {
logger.debug(SMS_API_AUTH_ID);
logger.debug(SMS_API_AUTH_TOKEN);
log.debug(SMS_API_AUTH_ID);
log.debug(SMS_API_AUTH_TOKEN);
Plivo.init(SMS_API_AUTH_ID, SMS_API_AUTH_TOKEN);
MessageCreateResponse response = Message.creator("19342227693", toPhoneNumber, msg).create();

logger.debug("sms sent to " + toPhoneNumber + " / msg: [" + msg + "]");
logger.debug("sms response msg: " + response.getMessage());
log.debug("sms sent to " + toPhoneNumber + " / msg: [" + msg + "]");
log.debug("sms response msg: " + response.getMessage());

rtn = true;

Expand All @@ -47,11 +45,11 @@ public boolean sendSMS(String toPhoneNumber, String msg) {
// }
//
// } catch (PlivoException e) {
// logger.info("Caught exception from the SMS third party, ------ " + e.getMessage());
// log.info("Caught exception from the SMS third party, ------ " + e.getMessage());
// }

} catch (Exception e) {
logger.info("Caught exception trying to send SMS, ------ " + e.getMessage());
log.info("Caught exception trying to send SMS, ------ " + e.getMessage());
}
}

Expand Down
Loading

0 comments on commit b4f7d5e

Please sign in to comment.