Project

General

Profile

« Previous | Next » 

Revision 48294

Delete file when claim is deleted and result has no other links| change semantics | change the openaireId generation

View differences:

ResultHandler.java
3 3
import eu.dnetlib.data.claims.migration.entity.Result;
4 4
import eu.dnetlib.data.claimsDemo.ClaimUtils;
5 5
import eu.dnetlib.data.claimsDemo.QueryGenerator;
6
import eu.dnetlib.data.claimsDemo.SQLStoreException;
6 7
import eu.dnetlib.data.claimsDemo.SqlDAO;
7 8
import org.apache.commons.io.FileUtils;
8 9
import org.apache.log4j.Logger;
9 10

  
10 11
import java.io.File;
11 12
import java.io.IOException;
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
12 15

  
13 16
/**
14 17
 * Created by kiatrop on 5/2/2016.
......
55 58
        return type+"/"+datasource+"/"+openaireId.replace("/","*");
56 59

  
57 60
    }
61
    public void deleteRecordFile(String type, String id) throws SQLStoreException, SQLException {
62
            ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateCountClaimsForResultQuery(id));
63
            if(rs.next()){
64
                Integer count =  rs.getInt(1);
65
                log.debug("Count is:" + count );
66

  
67
                if(count != null && count ==1){
68
                    ResultSet rs1 = sqlDAO.executePreparedQuery(queryGenerator.generateSelectResultSource(id));
69
                    if(rs1.next()){
70
                        String source =  rs1.getString(1);
71

  
72
                        log.debug("source is:" + source );
73
                        String path=createExportPath(type, source, id);
74
                         File file = new File(this.pathToSaveRecord+path);
75
                        log.debug("path is:" + path );
76

  
77

  
78
                        if (file.delete()) {
79
                            log.info(file.getName() + " is deleted!");
80
                        } else {
81
                            log.warn("Delete operation is failed for file "+ this.pathToSaveRecord+path);
82
                        }
83
                    }else{
84
                        log.error("Couldn't get result source for result with id : "+ id );
85

  
86
                    }
87

  
88
                }else{
89
                    log.info("This metadata file cannot be removed (count="+count+") for result with id : "+ id );
90
                }
91
            }else{
92
                log.error("Couldn't fetch claims count for result with id : "+ id );
93
            }
94
    }
95

  
58 96
    public SqlDAO getSqlDAO() {
59 97
        return sqlDAO;
60 98
    }

Also available in: Unified diff