src/main/java/org/vivoweb/harvester/ingest/GrantsFetchFromED.java
/**
		 * This method check for grants coming from Coeus whether they exist in VIVO
		 * @param grants the list of grants
		 * @param cwid unique identifier for faculty
		 */
This method check for grants coming from Coeus whether they exist in VIVO
@param grants the list of grants
@param cwid unique identifier for faculty
This method check for grants coming from Coeus whether they exist in VIVO @param grants the list of grants @param cwid unique identifier for faculty
private void checkGrantExistInVivo(List<GrantBean> grants, String cwid) {
			for(int i=0; i< grants.size(); i++) {
				String sparqlQuery = "PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
					 "PREFIX foaf:     <http://xmlns.com/foaf/0.1/> \n" +
					 "SELECT  (count(?o) as ?grant) \n" +
					 "WHERE \n" +
					 "{ \n" +
					 "GRAPH <http://vitro.mannlib.cornell.edu/a/graph/wcmcCoeus> {\n" +
					 "<" + this.vivoNamespace + "grant-" + grants.get(i).getAwardNumber().trim() + "> ?p ?o . \n" +
					 "}}";
				log.info("Checking grant " + grants.get(i));
				if(ingestType.equals(IngestType.VIVO_API.toString())) {
					try {
						String response = this.vivoClient.vivoQueryApi(sparqlQuery);
						log.info(response);
						JSONObject obj = new JSONObject(response);
						JSONArray bindings = obj.getJSONObject("results").getJSONArray("bindings");
						int count = bindings.getJSONObject(0).getJSONObject("grant").getInt("value");
						if(count > 0) {
							log.info("Grant- " + grants.get(i).getAwardNumber() + " exists in VIVO");
							checkForUpdates(grants.get(i), cwid, "UPDATE");
						}
						else {
							insertGrantsInVivo(grants.get(i),cwid,"INSERT");
							this.insertCount = this.insertCount + 1;
						}
					} catch(Exception e) {
						log.error("Api Exception", e);
					}
				} else if(ingestType.equals(IngestType.SDB_DIRECT.toString())){
					SDBJenaConnect vivoJena = this.jcf.getConnectionfromPool("dataSet");
					try {
						ResultSet rs = vivoJena.executeSelectQuery(sparqlQuery, true);
						QuerySolution qs = rs.nextSolution();
						int count = Integer.parseInt(qs.get("grant").toString().replace("^^http://www.w3.org/2001/XMLSchema#integer", ""));
						if(count > 0) {
							log.info("Grant- " + grants.get(i).getAwardNumber() + " exists in VIVO");
							this.jcf.returnConnectionToPool(vivoJena, "dataSet");
							checkForUpdates(grants.get(i), cwid, "UPDATE");
						}
						else {
							this.jcf.returnConnectionToPool(vivoJena, "dataSet");
							insertGrantsInVivo(grants.get(i),cwid,"INSERT");
							this.insertCount = this.insertCount + 1;
						}
					} catch(IOException e) {
						log.error("IOException" ,e);
					}
				} else {
					TDBJenaConnect vivoJena = this.tcf.getConnectionfromPool("dataSet");
					try {
						ResultSet rs = vivoJena.executeSelectQuery(sparqlQuery, true);
						QuerySolution qs = rs.nextSolution();
						int count = Integer.parseInt(qs.get("grant").toString().replace("^^http://www.w3.org/2001/XMLSchema#integer", ""));
						if(count > 0) {
							log.info("Grant- " + grants.get(i).getAwardNumber() + " exists in VIVO");
							this.tcf.returnConnectionToPool(vivoJena, "dataSet");
							checkForUpdates(grants.get(i), cwid, "UPDATE");
						}
						else {
							this.tcf.returnConnectionToPool(vivoJena, "dataSet");
							insertGrantsInVivo(grants.get(i),cwid,"INSERT");
							this.insertCount = this.insertCount + 1;
						}
					} catch(IOException e) {
						log.error("IOException" ,e);
					}
				}
			}
		}
private void checkGrantExistInVivo ( List < GrantBean > grants , String cwid ) { for ( int i = 0 ; i < grants . size ( ) ; i ++ ) { String sparqlQuery = "PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "PREFIX foaf:     <http://xmlns.com/foaf/0.1/> \n" + "SELECT  (count(?o) as ?grant) \n" + "WHERE \n" + "{ \n" + "GRAPH <http://vitro.mannlib.cornell.edu/a/graph/wcmcCoeus> {\n" + "<" + this . vivoNamespace + "grant-" + grants . get ( i ) . getAwardNumber ( ) . trim ( ) + "> ?p ?o . \n" + "}}" ; log . info ( "Checking grant " + grants . get ( i ) ) ; if ( ingestType . equals ( IngestType . VIVO_API . toString ( ) ) ) { try { String response = this . vivoClient . vivoQueryApi ( sparqlQuery ) ; log . info ( response ) ; JSONObject obj = new JSONObject ( response ) ; JSONArray bindings = obj . getJSONObject ( "results" ) . getJSONArray ( "bindings" ) ; int count = bindings . getJSONObject ( 0 ) . getJSONObject ( "grant" ) . getInt ( "value" ) ; if ( count > 0 ) { log . info ( "Grant- " + grants . get ( i ) . getAwardNumber ( ) + " exists in VIVO" ) ; checkForUpdates ( grants . get ( i ) , cwid , "UPDATE" ) ; } else { insertGrantsInVivo ( grants . get ( i ) , cwid , "INSERT" ) ; this . insertCount = this . insertCount + 1 ; } } catch ( Exception e ) { log . error ( "Api Exception" , e ) ; } } else if ( ingestType . equals ( IngestType . SDB_DIRECT . toString ( ) ) ) { SDBJenaConnect vivoJena = this . jcf . getConnectionfromPool ( "dataSet" ) ; try { ResultSet rs = vivoJena . executeSelectQuery ( sparqlQuery , true ) ; QuerySolution qs = rs . nextSolution ( ) ; int count = Integer . parseInt ( qs . get ( "grant" ) . toString ( ) . replace ( "^^http://www.w3.org/2001/XMLSchema#integer" , "" ) ) ; if ( count > 0 ) { log . info ( "Grant- " + grants . get ( i ) . getAwardNumber ( ) + " exists in VIVO" ) ; this . jcf . returnConnectionToPool ( vivoJena , "dataSet" ) ; checkForUpdates ( grants . get ( i ) , cwid , "UPDATE" ) ; } else { this . jcf . returnConnectionToPool ( vivoJena , "dataSet" ) ; insertGrantsInVivo ( grants . get ( i ) , cwid , "INSERT" ) ; this . insertCount = this . insertCount + 1 ; } } catch ( IOException e ) { log . error ( "IOException" , e ) ; } } else { TDBJenaConnect vivoJena = this . tcf . getConnectionfromPool ( "dataSet" ) ; try { ResultSet rs = vivoJena . executeSelectQuery ( sparqlQuery , true ) ; QuerySolution qs = rs . nextSolution ( ) ; int count = Integer . parseInt ( qs . get ( "grant" ) . toString ( ) . replace ( "^^http://www.w3.org/2001/XMLSchema#integer" , "" ) ) ; if ( count > 0 ) { log . info ( "Grant- " + grants . get ( i ) . getAwardNumber ( ) + " exists in VIVO" ) ; this . tcf . returnConnectionToPool ( vivoJena , "dataSet" ) ; checkForUpdates ( grants . get ( i ) , cwid , "UPDATE" ) ; } else { this . tcf . returnConnectionToPool ( vivoJena , "dataSet" ) ; insertGrantsInVivo ( grants . get ( i ) , cwid , "INSERT" ) ; this . insertCount = this . insertCount + 1 ; } } catch ( IOException e ) { log . error ( "IOException" , e ) ; } } } }
This method check for grants coming from Coeus whether they exist in VIVO
 @param grants the list of grants
 @param cwid unique identifier for faculty
This method check for grants coming from Coeus whether they exist in VIVO @param grants the list of grants @param cwid unique identifier for faculty
//"FROM <http://vitro.mannlib.cornell.edu/a/graph/wcmcCoeus> \n" + //This is done to return the connection for coeus since it is being used again in the update function //This is done to return the connection for coeus since it is being used again in the update function //This is done to return the connection for coeus since it is being used again in the update function