<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.medlog.webservice.dao;

import static com.medlog.webservice.CONST.API_ACTIONS.*;
import static com.medlog.webservice.CONST.DB_STRINGS.*;
import static com.medlog.webservice.CONST.SETTINGS.*;
import com.medlog.webservice.sql.*;
import com.medlog.webservice.util.*;
import com.medlog.webservice.vo.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;

/**
 * Implementation of {@linkplain IMedLogDAO}
 *
 * @author (c)2016
 */
public class MedLogDAO implements IMedLogDAO {

/**
 * Diary selection base
 *
 * @param _id
 * @param _keyword
 * @return
 */
private ArrayList<DiaryVO> findDiary(int _id, String _keyword) {
   ArrayList<DiaryVO> voList = new ArrayList<DiaryVO>();
   _keyword = StrUtl.toS( _keyword );

   CallableStatement cs = null;
   ResultSet rs = null;
   boolean valid = false;
   try {
	  cs = db.getConnnection().prepareCall( SP_DIARY_SELECT );
	  if ( _id > 0 ) {
		 cs.setInt( 1, _id );
		 valid = true;
	  } else {
		 cs.setNull( 1, java.sql.Types.INTEGER );
	  }
	  cs.setInt( 2, getCurrentUser().getPatientID() );
	  if ( _keyword.isEmpty() ) {
		 cs.setNull( 3, java.sql.Types.NVARCHAR );
	  } else {
		 valid = true;
		 cs.setString( 3, _keyword );
		 cs.setNull( 3, java.sql.Types.NVARCHAR );
	  }

	  if ( valid ) {
		 rs = cs.executeQuery();
		 while ( rs.next() ) {

		 }
	  } else {
		 this.stateOK = false;
		 this.errorMessage = "com.medlog.webservice.dao.MedLogDAO.findPatient() - Invalid Params: Username is required";
		 if ( DEBUG ) {
			LOG.severe( this.errorMessage );
		 }
	  }
   } catch (SQLException ex) {
	  LOG.log( Level.SEVERE, null, ex );
   } finally {
	  DbUtl.close( rs );
	  DbUtl.close( cs );
   }
   return voList;
}

@Override
public ArrayList<DiaryVO> findDiaryByKeyword(String _keyword) {
   return findDiary( 0, StrUtl.toS( _keyword ) );
}

@Override<commit_msg>Added diary: SQLRS->pojo & populate diary<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.medlog.webservice.dao;

import static com.medlog.webservice.CONST.API_ACTIONS.*;
import static com.medlog.webservice.CONST.DB_STRINGS.*;
import static com.medlog.webservice.CONST.SETTINGS.*;
import com.medlog.webservice.sql.*;
import com.medlog.webservice.util.*;
import com.medlog.webservice.vo.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;

/**
 * Implementation of {@linkplain IMedLogDAO}
 *
 * @author (c)2016
 */
public class MedLogDAO implements IMedLogDAO {

/**
 * Diary selection base
 *
 * @param _id
 * @param _keyword
 * @return
 */
private ArrayList<DiaryVO> findDiary(int _id, String _keyword) {
   ArrayList<DiaryVO> voList = new ArrayList<DiaryVO>();
   _keyword = StrUtl.toS( _keyword );

   CallableStatement cs = null;
   ResultSet rs = null;
   boolean valid = false;
   try {
	  cs = db.getConnnection().prepareCall( SP_DIARY_SELECT );
	  if ( _id > 0 ) {
		 cs.setInt( 1, _id );
		 valid = true;
	  } else {
		 cs.setNull( 1, java.sql.Types.INTEGER );
	  }
	  cs.setInt( 2, getCurrentUser().getPatientID() );
	  if ( _keyword.isEmpty() ) {
		 cs.setNull( 3, java.sql.Types.NVARCHAR );
	  } else {
		 valid = true;
		 cs.setString( 3, _keyword );
		 cs.setNull( 3, java.sql.Types.NVARCHAR );
	  }

	  if ( valid ) {
		 rs = cs.executeQuery();
		 while ( rs.next() ) {
			voList.add( DiaryVO.builder()
					.id( rs.getInt( "id" ) )
					.title( rs.getString( "title" ) )
					.notes( rs.getString( "notes" ) )
					.mood( rs.getInt( "mood" ) )
					.productivity( rs.getInt( "productivity" ) )
					.patientID( getCurrentUser() )
					.createdDate( rs.getDate( "createdDate" ) )
					.build() );
		 }
	  } else {
		 this.stateOK = false;
		 this.errorMessage = "com.medlog.webservice.dao.MedLogDAO.findPatient() - Invalid Params: Username is required";
		 if ( DEBUG ) {
			LOG.severe( this.errorMessage );
		 }
	  }
   } catch (SQLException ex) {
	  LOG.log( Level.SEVERE, null, ex );
   } finally {
	  DbUtl.close( rs );
	  DbUtl.close( cs );
   }
   return voList;
}

@Override
public ArrayList<DiaryVO> findDiaryByKeyword(String _keyword) {
   return findDiary( 0, StrUtl.toS( _keyword ) );
}

@Override
{'fraction_non_alphanumeric': 0.1408355795148248, 'fraction_numerical': 0.005390835579514825, 'mean_word_length': 3.2490458015267176, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7659839', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1526, 'n_words': 364}