Ignore:
Timestamp:
04/08/10 10:38:59 (9 years ago)
Author:
mnagni
Message:

Minor changes to some Exception strategy

Location:
RevitalizationWS/ws/DiscoveryService/trunk/src/main/java/ndg/services
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • RevitalizationWS/ws/DiscoveryService/trunk/src/main/java/ndg/services/discovery/model/CommonMethods.java

    r7217 r7267  
    1111import ndg.common.NdgMessage; 
    1212import ndg.common.exception.AssembleQueryException; 
    13 import ndg.common.exception.NdgException; 
    1413import ndg.common.exception.NdgSQLException; 
    1514import ndg.common.exception.ResourceNotAvailable; 
     
    121120         
    122121        String assembleSearch(SearchCriteria criteria, RetrieveCriteriaType retrieveType)  
    123                         throws NdgException{ 
     122                throws AssembleQueryException{ 
    124123 
    125124                // NB, we use the postgres text search function to do term searches 
  • RevitalizationWS/ws/DiscoveryService/trunk/src/main/java/ndg/services/discovery/model/PresentAgent.java

    r7217 r7267  
    1515import ndg.common.NdgLogger; 
    1616import ndg.common.NdgMessage; 
     17import ndg.common.exception.AssembleQueryException; 
    1718import ndg.common.exception.NdgException; 
    1819import ndg.common.exception.NdgSQLException; 
     
    2122import ndg.services.discovery.basic.DiscoveryDictionary; 
    2223import ndg.services.discovery.basic.DiscoveryDictionary.OriginalDocumentToTable; 
     24import ndg.services.jpa.OriginalDocument; 
    2325import ndg.services.schemas.discovery.BoundingBoxType; 
    2426import ndg.services.schemas.discovery.DateRangeType; 
     
    2830import ndg.services.schemas.discovery.TemporalType; 
    2931import ndg.services.schemas.discovery.SearchType.SearchCriteria; 
    30 import ndg.services.jpa.OriginalDocument; 
    3132 
    3233import org.apache.log4j.Level; 
     
    203204         */ 
    204205        public List<OriginalDocument> doPresent(Connection conn, List<String> documentsId, RetrieveCriteriaType type) 
    205                         throws NdgException { 
     206                        throws NdgSQLException, AssembleQueryException, ResourceNotAvailable { 
    206207                if (documentsId == null || documentsId.size() == 0) 
    207208                        return new ArrayList<OriginalDocument>(); 
     
    276277                        start = rs.getTimestamp("start_time"); 
    277278                        if (start != null) { 
    278                                 calendar = calendar.getInstance(); 
     279                                calendar = Calendar.getInstance(); 
    279280                                calendar.setTimeInMillis(start.getTime()); 
    280281                        } else { 
     
    287288                        end = rs.getTimestamp("end_time"); 
    288289                        if (end != null) { 
    289                                 calendar = calendar.getInstance(); 
     290                                calendar = Calendar.getInstance(); 
    290291                                calendar.setTimeInMillis(end.getTime()); 
    291292                        } else { 
  • RevitalizationWS/ws/DiscoveryService/trunk/src/main/java/ndg/services/discovery/model/SearchAgent.java

    r7217 r7267  
    9090                        // NdgMessage msg = new NdgMessage("sql.resultset.parsing.error", 
    9191                        // new Object[] { sqlQuery }); 
    92                 } catch (NdgException e) { 
    93                         logHelper.logMessage(e, Level.ERROR); 
    94                         throw new NdgException(e.getBundlMessage()); 
    9592                } finally { 
    9693                        commitOrRollback(conn, commit); 
     
    112109         *             if an error during the database access 
    113110         **/ 
    114         private List<OriginalDocument> searchDocuments(Connection conn, SearchCriteria criteria) throws NdgException { 
     111        private List<OriginalDocument> searchDocuments(Connection conn, SearchCriteria criteria) throws AssembleQueryException, NdgSQLException, ResourceNotAvailable { 
    115112                List<OriginalDocument> res = new ArrayList<OriginalDocument>(); 
    116113                List<String> toFilter = executeSearch(conn, assembleSearch(criteria, searchType.getRetrieveCriteria())); 
  • RevitalizationWS/ws/DiscoveryService/trunk/src/main/java/ndg/services/schemas/discovery/DiscoveryServiceSkeleton.java

    r7240 r7267  
    44import java.lang.reflect.InvocationTargetException; 
    55import java.sql.Connection; 
    6 import java.sql.PreparedStatement; 
    76import java.sql.SQLException; 
    8 import java.sql.Timestamp; 
    97import java.util.ArrayList; 
    10 import java.util.Calendar; 
    118import java.util.List; 
    129 
     
    1411import ndg.common.NdgMessage; 
    1512import ndg.common.exception.NdgException; 
    16 import ndg.common.exception.ResourceNotAvailable; 
    1713import ndg.services.discovery.basic.DiscoveryBasic; 
    1814import ndg.services.discovery.basic.DiscoveryDictionary; 
     
    2319import ndg.services.discovery.model.SearchAgent; 
    2420import ndg.services.jpa.OriginalDocument; 
    25 import ndg.services.schemas.discovery.CustomInfo; 
    26 import ndg.services.schemas.discovery.DiscoveryServiceSkeletonInterface; 
    27 import ndg.services.schemas.discovery.DoPresentDocument; 
    28 import ndg.services.schemas.discovery.DoPresentReturnDocument; 
    29 import ndg.services.schemas.discovery.DoSearchDocument; 
    30 import ndg.services.schemas.discovery.DoSearchReturnDocument; 
    31 import ndg.services.schemas.discovery.Documents; 
    32 import ndg.services.schemas.discovery.GetListDocument; 
    33 import ndg.services.schemas.discovery.GetListNamesDocument; 
    34 import ndg.services.schemas.discovery.GetListNamesReturnDocument; 
    35 import ndg.services.schemas.discovery.GetListNamesReturnType; 
    36 import ndg.services.schemas.discovery.GetListReturnDocument; 
    37 import ndg.services.schemas.discovery.GetListReturnType; 
    38 import ndg.services.schemas.discovery.GetListType; 
    39 import ndg.services.schemas.discovery.OrderByType; 
    40 import ndg.services.schemas.discovery.OrderingMetricType; 
    41 import ndg.services.schemas.discovery.PresentReturnType; 
    42 import ndg.services.schemas.discovery.RetrieveCriteriaType; 
    43 import ndg.services.schemas.discovery.ReturnBriefType; 
    44 import ndg.services.schemas.discovery.ReturnFullType; 
    45 import ndg.services.schemas.discovery.ReturnSimpleType; 
    46 import ndg.services.schemas.discovery.ReturnSummaryType; 
    47 import ndg.services.schemas.discovery.SearchReturnType; 
    48 import ndg.services.schemas.discovery.SearchType; 
    49 import ndg.services.schemas.discovery.SimpleDocument1; 
    50 import ndg.services.schemas.discovery.TermSearchType; 
    5121import ndg.services.schemas.discovery.SearchType.SearchCriteria; 
    5222 
    53 import org.apache.axis2.context.MessageContext; 
    5423import org.apache.log4j.Level; 
    5524 
     
    6029 */ 
    6130public class DiscoveryServiceSkeleton implements DiscoveryServiceSkeletonInterface { 
    62  
    63         private static String insLogSQL = "INSERT INTO discoverySearchLogging(search_term, date_of_search, scope, originator_IP, number_results_returned) values (?,?,?,?,?)"; 
    6431 
    6532        private NdgLogger logHelper = DiscoveryBasic.getInstance().getNdgInstance( 
     
    431398                type.setDocumentId(result.getOriginalDocumentFilename()); 
    432399        } 
    433  
    434         private void logClientIP(SearchReturnType responseContent, DoSearchDocument doSearch) { 
    435                 String ipAddress = ""; 
    436                 MessageContext messageContext = MessageContext.getCurrentMessageContext(); 
    437                 if (messageContext != null) { 
    438                         ipAddress = (String) messageContext.getProperty(MessageContext.REMOTE_ADDR); 
    439                 } 
    440                 try { 
    441                         insertInLogDB(doSearch, responseContent, ipAddress); 
    442                 } catch (ResourceNotAvailable e) { 
    443                         // TODO Auto-generated catch block 
    444                         e.printStackTrace(); 
    445                 } catch (SQLException e) { 
    446                         // TODO Auto-generated catch block 
    447                         e.printStackTrace(); 
    448                 } 
    449                 NdgMessage msg = new NdgMessage("client.ip", new Object[] { ipAddress }); 
    450                 logHelper.logMessage(msg, Level.INFO); 
    451         } 
    452  
    453         private void insertInLogDB(DoSearchDocument doSearch, SearchReturnType responseContent, String clientIP) 
    454                         throws SQLException, ResourceNotAvailable { 
    455                 Connection conn = DiscoveryBasic.getInstance().getLogConnection(); 
    456                 PreparedStatement stat = conn.prepareStatement(insLogSQL); 
    457                 String termSearch = doSearch.getDoSearch() != null ? assembleTermSearch(doSearch.getDoSearch() 
    458                                 .getSearchCriteria()) : null; 
    459                 stat.setString(1, termSearch); 
    460                 stat.setTimestamp(2, new Timestamp(Calendar.getInstance().getTimeInMillis())); 
    461                 String scope = doSearch.getDoSearch() != null ? getScope(doSearch.getDoSearch().getScopeArray()) : null; 
    462                 stat.setString(3, scope); 
    463                 stat.setString(4, clientIP); 
    464                 stat.setInt(5, responseContent.getHits()); 
    465                 stat.executeUpdate(); 
    466                 if (conn != null) 
    467                         conn.close(); 
    468         } 
    469  
    470         private String getScope(String[] scopes) { 
    471                 StringBuffer sb = new StringBuffer(); 
    472                 for (String item : scopes) { 
    473                         sb.append(item); 
    474                         sb.append(", "); 
    475                 } 
    476                 if (sb.length() > 0) 
    477                         sb.delete(sb.length() - 2, sb.length()); 
    478                 return sb.toString(); 
    479         } 
    480  
    481         private String assembleTermSearch(SearchCriteria criteria) { 
    482                 StringBuffer sb = new StringBuffer(); 
    483                 for (TermSearchType ts : criteria.getTermSearchArray()) { 
    484                         sb.append(ts.getTerm()); 
    485                         sb.append(", "); 
    486                 } 
    487                 if (sb.length() > 0) 
    488                         sb.delete(sb.length() - 2, sb.length()); 
    489                 return sb.toString(); 
    490         } 
    491400} 
Note: See TracChangeset for help on using the changeset viewer.