Link to home
Start Free TrialLog in
Avatar of roy_sanu
roy_sanuFlag for India

asked on

Code Review Please...

Dear Experts,

let us know if logger is good for production or we have remove it out ? is that slows down at the applicationl level ?
if we use only after catch is that ok..
logger.warn("proceeding with incomplete request from mobile: {}. cause: {}, message: {}", 
					requestBody.length(), ex.getCause(), ex.getMessage());

Open in new window

let us know  in our application we are using hashmap  is that good or map would be good ?
	@CrossOrigin
	@RequestMapping(value = beneficiaryURL, method = RequestMethod.POST, produces = {"application/json" })
	public HashMap<String, Object> screeningRecord(@RequestBody String requestBody, 
			HttpServletRequest request) throws Exception {
		String remoteAddr = request.getRemoteAddr();
		logger.info("got request from: {}", remoteAddr);
		logger.debug("{}: received message: {}", remoteAddr, requestBody);
		HashMap<String, Object> screeningRespone = new HashMap<>();	
		// Transaction id is generated
		String transactionId = String.format("%s-%s", UUID.randomUUID().toString(), 
				dateTimeFormatter.format(new Date()));
		logger.info("{}: Generated id: {}, url: {}. Saving...", remoteAddr, 
				transactionId, beneficiaryURL);
		SubmissionInfo submissionInfo = new SubmissionInfo(transactionId, requestBody, 
				SubmissionInfo.PENDING, beneficiaryURL);
		Integer partition = null;
		try {
			Map<String, Object> jsonRequest = load(requestBody);
			Long microPlanId = Long.valueOf(jsonRequest.get("microPlanId").toString());
			partition = (int) Math.abs(microPlanId % mobileUploadPartitionSize);
			int beneficiaryCount = ((List) jsonRequest.getOrDefault("beneficiaryData", 
					Arrays.asList())).size();
			submissionInfo.setBeneficiaryCount(beneficiaryCount);
			submissionInfo.setTeamname(jsonRequest.getOrDefault("teamName", UNDECLARED).toString());
			submissionInfo.setInstitutionCode(jsonRequest.getOrDefault("institutionCode", 
					UNDECLARED).toString());
			submissionInfo.setDaySignOffID(jsonRequest.getOrDefault("daySignOffID", 
					UNDECLARED).toString());
			String screeningDateUnix = jsonRequest.get("screeningDate").toString();
			if(screeningDateUnix != null)
				submissionInfo.setScreeningDate(new Date(Long.valueOf(screeningDateUnix)));
		}
		catch(Exception ex) {
			logger.warn("proceeding with incomplete request from mobile: {}. cause: {}, message: {}", 
					requestBody.length(), ex.getCause(), ex.getMessage());
			//ex.printStackTrace();
		}

Open in new window


Thanks
Roy...
Avatar of ste5an
ste5an
Flag of Germany image

Both questions could not be answered sincerely, cause they are performance related. Thus the entire architecture is important as well as how you're hosting your application.

The only things about your actual code:

You're catching a general exception (which is bad).

I would normally use a factory method or a builder in this case. Cause you should for sure refactor your code and extract this part. Then you can control there the amount of warnings logged. Especially as this would be the place for sanitation and validation of the user input. Which currently seems to miss entirely.

Your SubmissionInfo class seems to be a bit of a mess..
Why does it store the actual plain request and decoupled from it its properties? This allows the request and the properties to contain different, contradicting values.
Why do you need to create the transaction ID manually? This should be retrieved from a generator.
Avatar of roy_sanu

ASKER


I would normally use a factory method or a builder in this case
can we provide me a sample of your understanding on the code so that  i could take it forward from there..

Thanks
roy
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Stefan