src/main/java/org/vivoweb/harvester/operations/DeleteProfile.java
/**
	 * Execute method to perform all the steps needed for successful deletion
	 */
Execute method to perform all the steps needed for successful deletion
Execute method to perform all the steps needed for successful deletion
public void execute() {
		int inActiveCount = 0;
		int activeCount = 0;
		List<String> people = edi.getPeopleInVivo();
		if(people.isEmpty())
			logger.info("No People needs to be deleted");
		logger.info("Checking in all other graph");
		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  distinct ?people \n" +
			 "WHERE \n" +
			 "{ GRAPH ?g {\n" +
			 "?people rdf:type foaf:Person . \n" +
			 "FILTER(REGEX(STR(?people),\"" + this.vivoNamespace + "cwid-\")) \n" +
			 "}}";
		if(ingestType.equals(IngestType.VIVO_API.toString())) {
			try {
				String response = this.vivoClient.vivoQueryApi(sparqlQuery);
				logger.info(response);
				JSONObject obj = new JSONObject(response);
				JSONArray bindings = obj.getJSONObject("results").getJSONArray("bindings");
				if(bindings != null && !bindings.isEmpty()) {
					for (int i = 0; i < bindings.length(); ++i) {
						if(bindings.getJSONObject(i).optJSONObject("people") != null && bindings.getJSONObject(i).optJSONObject("people").has("value")) {
							people.add(bindings.getJSONObject(i).getJSONObject("people").getString("value").replace(this.vivoNamespace + "cwid-", "").trim());
						}
					}
				}
			} catch(Exception e) {
				logger.error("Api Exception", e);
			}
		} else {
			SDBJenaConnect vivoJena = this.jcf.getConnectionfromPool("dataSet");
			ResultSet rs;
			try {
				rs = vivoJena.executeSelectQuery(sparqlQuery,true);
			while(rs.hasNext())
			{
				QuerySolution qs =rs.nextSolution();
				if(qs.get("people") != null && !people.contains(qs.get("people").toString().replace(this.vivoNamespace + "cwid-", "").trim())) {
					people.add(qs.get("people").toString().replace(this.vivoNamespace + "cwid-", "").trim());
				}
			}
			} catch(IOException e) {
				logger.info("IOException" , e);
			}
			this.jcf.returnConnectionToPool(vivoJena, "dataSet");
		}
		Iterator<String> it = people.iterator();
		while(it.hasNext()) {
			String cwid = it.next().trim();
			if(!checkForInActivePeopleEd(cwid)) {
				List<PublicationBean> publications = new ArrayList<PublicationBean>();
				Map<String, String> grants = new HashMap<String, String>();
				logger.info("###########################################");
				logger.info("Cwid - " + cwid + " needs to be deleted");
				logger.info("Getting list of publications for " + cwid);
				getListofPublications(cwid, publications);
				logger.info("Getting list of grants for " + cwid);
				getListOfGrants(cwid, grants);
				if(publications.isEmpty()) {
					try {
						deleteProfile(cwid, publications, grants);
						logger.info("Pubs is empty");
					} catch(IOException e) {
						logger.info("IOException", e);
					}
				}
				else {
					 	checkAdditionalWCMCAuthoredPubs(publications);
					 	for(PublicationBean pb : publications) {
							logger.info(pb.toString());
						}
					try {
						deleteProfile(cwid, publications, grants);
					} catch(IOException e) {
						logger.info("IOException", e);
					}
					addAuthorAsExternalEntity(cwid, publications);
				}
				deleteRemainingTriples(cwid);
				logger.info("###########################################");
				inActiveCount = inActiveCount + 1;
			}
			else {
				logger.info("Cwid: " + cwid + " does not have to be deleted");
				activeCount = activeCount + 1;
			}
		}
		logger.info("Total inactive profile deleted: " + inActiveCount);
		logger.info("Total active profiles in VIVO: " + activeCount);
	}
public void execute ( ) { int inActiveCount = 0 ; int activeCount = 0 ; List < String > people = edi . getPeopleInVivo ( ) ; if ( people . isEmpty ( ) ) logger . info ( "No People needs to be deleted" ) ; logger . info ( "Checking in all other graph" ) ; 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  distinct ?people \n" + "WHERE \n" + "{ GRAPH ?g {\n" + "?people rdf:type foaf:Person . \n" + "FILTER(REGEX(STR(?people),\"" + this . vivoNamespace + "cwid-\")) \n" + "}}" ; if ( ingestType . equals ( IngestType . VIVO_API . toString ( ) ) ) { try { String response = this . vivoClient . vivoQueryApi ( sparqlQuery ) ; logger . info ( response ) ; JSONObject obj = new JSONObject ( response ) ; JSONArray bindings = obj . getJSONObject ( "results" ) . getJSONArray ( "bindings" ) ; if ( bindings != null && ! bindings . isEmpty ( ) ) { for ( int i = 0 ; i < bindings . length ( ) ; ++ i ) { if ( bindings . getJSONObject ( i ) . optJSONObject ( "people" ) != null && bindings . getJSONObject ( i ) . optJSONObject ( "people" ) . has ( "value" ) ) { people . add ( bindings . getJSONObject ( i ) . getJSONObject ( "people" ) . getString ( "value" ) . replace ( this . vivoNamespace + "cwid-" , "" ) . trim ( ) ) ; } } } } catch ( Exception e ) { logger . error ( "Api Exception" , e ) ; } } else { SDBJenaConnect vivoJena = this . jcf . getConnectionfromPool ( "dataSet" ) ; ResultSet rs ; try { rs = vivoJena . executeSelectQuery ( sparqlQuery , true ) ; while ( rs . hasNext ( ) ) { QuerySolution qs = rs . nextSolution ( ) ; if ( qs . get ( "people" ) != null && ! people . contains ( qs . get ( "people" ) . toString ( ) . replace ( this . vivoNamespace + "cwid-" , "" ) . trim ( ) ) ) { people . add ( qs . get ( "people" ) . toString ( ) . replace ( this . vivoNamespace + "cwid-" , "" ) . trim ( ) ) ; } } } catch ( IOException e ) { logger . info ( "IOException" , e ) ; } this . jcf . returnConnectionToPool ( vivoJena , "dataSet" ) ; } Iterator < String > it = people . iterator ( ) ; while ( it . hasNext ( ) ) { String cwid = it . next ( ) . trim ( ) ; if ( ! checkForInActivePeopleEd ( cwid ) ) { List < PublicationBean > publications = new ArrayList < PublicationBean > ( ) ; Map < String , String > grants = new HashMap < String , String > ( ) ; logger . info ( "###########################################" ) ; logger . info ( "Cwid - " + cwid + " needs to be deleted" ) ; logger . info ( "Getting list of publications for " + cwid ) ; getListofPublications ( cwid , publications ) ; logger . info ( "Getting list of grants for " + cwid ) ; getListOfGrants ( cwid , grants ) ; if ( publications . isEmpty ( ) ) { try { deleteProfile ( cwid , publications , grants ) ; logger . info ( "Pubs is empty" ) ; } catch ( IOException e ) { logger . info ( "IOException" , e ) ; } } else { checkAdditionalWCMCAuthoredPubs ( publications ) ; for ( PublicationBean pb : publications ) { logger . info ( pb . toString ( ) ) ; } try { deleteProfile ( cwid , publications , grants ) ; } catch ( IOException e ) { logger . info ( "IOException" , e ) ; } addAuthorAsExternalEntity ( cwid , publications ) ; } deleteRemainingTriples ( cwid ) ; logger . info ( "###########################################" ) ; inActiveCount = inActiveCount + 1 ; } else { logger . info ( "Cwid: " + cwid + " does not have to be deleted" ) ; activeCount = activeCount + 1 ; } } logger . info ( "Total inactive profile deleted: " + inActiveCount ) ; logger . info ( "Total active profiles in VIVO: " + activeCount ) ; }
Execute method to perform all the steps needed for successful deletion
Execute method to perform all the steps needed for successful deletion
//"MINUS { \n" + //"graph <http://vitro.mannlib.cornell.edu/a/graph/wcmcPeople> {?people rdf:type foaf:Person .} \n" + //"}\n" + //logger.info(sparqlQuery); // TODO Auto-generated catch block // TODO Auto-generated catch block