6 |
6 |
import org.apache.commons.logging.Log;
|
7 |
7 |
import org.apache.commons.logging.LogFactory;
|
8 |
8 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
9 |
import org.springframework.beans.factory.annotation.Value;
|
9 |
10 |
import org.springframework.stereotype.Service;
|
10 |
11 |
import org.springframework.transaction.annotation.Transactional;
|
11 |
12 |
|
|
13 |
import javax.annotation.PostConstruct;
|
12 |
14 |
import javax.persistence.criteria.CriteriaBuilder;
|
13 |
15 |
import java.io.*;
|
14 |
16 |
import java.io.File;
|
... | ... | |
40 |
42 |
@Autowired
|
41 |
43 |
private OrganizationManager organizationManager;
|
42 |
44 |
|
|
45 |
@Value("${goldoa.fundingbids}")
|
|
46 |
private String fungindBids;
|
|
47 |
|
43 |
48 |
private Log LOGGER = LogFactory.getLog(RequestManagerImpl.class);
|
44 |
49 |
|
45 |
|
|
|
50 |
@PostConstruct
|
|
51 |
public void init(){
|
|
52 |
LOGGER.debug("Funding bids property: " + fungindBids);
|
|
53 |
}
|
46 |
54 |
public void importAlternativeFundingBids(){
|
47 |
55 |
|
48 |
|
String path = "http://195.134.66.230:8380/uploadFiles/";
|
49 |
|
BufferedReader br = null;
|
50 |
|
String s = "";
|
51 |
|
String cvsSplitBy = ",";
|
52 |
|
AlternativeFundingBid bid = null;
|
|
56 |
if(Boolean.parseBoolean(fungindBids)){
|
|
57 |
String path = "http://195.134.66.230:8380/uploadFiles/";
|
|
58 |
BufferedReader br = null;
|
|
59 |
String s = "";
|
|
60 |
String cvsSplitBy = ",";
|
|
61 |
AlternativeFundingBid bid = null;
|
53 |
62 |
|
54 |
|
try {
|
55 |
|
URL url = null;
|
56 |
|
URLConnection urlConnection = null;
|
57 |
63 |
try {
|
58 |
|
url = new URL(path + "AlternativeFundingBids-FirstRound.csv");
|
59 |
|
urlConnection = url.openConnection();
|
60 |
|
} catch (IOException e) {
|
61 |
|
LOGGER.debug(e);
|
62 |
|
}
|
63 |
|
br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
64 |
|
s = br.readLine();
|
65 |
|
while ((s = br.readLine()) != null) {
|
|
64 |
URL url = null;
|
|
65 |
URLConnection urlConnection = null;
|
|
66 |
try {
|
|
67 |
url = new URL(path + "AlternativeFundingBids-FirstRound.csv");
|
|
68 |
urlConnection = url.openConnection();
|
|
69 |
} catch (IOException e) {
|
|
70 |
LOGGER.debug(e);
|
|
71 |
}
|
|
72 |
br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
|
73 |
s = br.readLine();
|
|
74 |
while ((s = br.readLine()) != null) {
|
66 |
75 |
|
67 |
|
LOGGER.debug("Line -> " + s);
|
|
76 |
LOGGER.debug("Line -> " + s);
|
68 |
77 |
|
69 |
|
String[] line = s.split(cvsSplitBy);
|
70 |
|
String id = !line[0].equals("")?line[0].trim():null;
|
71 |
|
String funding_name = !line[1].equals("")?line[1].trim():null;
|
72 |
|
String folder_name = !line[3].equals("")?line[3].trim():null;
|
73 |
|
String organization = !line[2].equals("")?line[2].trim():null;
|
74 |
|
String country = !line[4].equals("")?line[4].trim():null;
|
75 |
|
String totalAmount = !line[5].equals("")?line[5].trim():null;
|
76 |
|
String contractStartDate = !line[6].equals("")?line[6].trim():null;
|
77 |
|
String contractEndDate = !line[7].equals("")?line[7].trim():null;
|
|
78 |
String[] line = s.split(cvsSplitBy);
|
|
79 |
String id = !line[0].equals("")?line[0].trim():null;
|
|
80 |
String funding_name = !line[1].equals("")?line[1].trim():null;
|
|
81 |
String folder_name = !line[3].equals("")?line[3].trim():null;
|
|
82 |
String organization = !line[2].equals("")?line[2].trim():null;
|
|
83 |
String country = !line[4].equals("")?line[4].trim():null;
|
|
84 |
String totalAmount = !line[5].equals("")?line[5].trim():null;
|
|
85 |
String contractStartDate = !line[6].equals("")?line[6].trim():null;
|
|
86 |
String contractEndDate = !line[7].equals("")?line[7].trim():null;
|
78 |
87 |
|
79 |
|
String firstInvoiceDate = !line[8].equals("")?line[8].trim():null;
|
80 |
|
String firstInvoiceNumber = !line[9].equals("")?line[9].trim():null;
|
|
88 |
String firstInvoiceDate = !line[8].equals("")?line[8].trim():null;
|
|
89 |
String firstInvoiceNumber = !line[9].equals("")?line[9].trim():null;
|
81 |
90 |
|
82 |
|
String secondInvoiceDate = !line[10].equals("")?line[10].trim():null;
|
83 |
|
String secondInvoiceNumber = !line[11].equals("")?line[11].trim():null;
|
|
91 |
String secondInvoiceDate = !line[10].equals("")?line[10].trim():null;
|
|
92 |
String secondInvoiceNumber = !line[11].equals("")?line[11].trim():null;
|
84 |
93 |
|
85 |
|
String firstPaymentAmount = !line[12].equals("")?line[12].trim():null;
|
86 |
|
String firstPaymentDate = !line[13].equals("")?line[13].trim():null;
|
87 |
|
String firstPaymentOtherCosts = !line[14].equals("")?line[14].trim():null;
|
88 |
|
String firstPaymentTransferCost = !line[15].equals("")?line[15].trim():null;
|
|
94 |
String firstPaymentAmount = !line[12].equals("")?line[12].trim():null;
|
|
95 |
String firstPaymentDate = !line[13].equals("")?line[13].trim():null;
|
|
96 |
String firstPaymentOtherCosts = !line[14].equals("")?line[14].trim():null;
|
|
97 |
String firstPaymentTransferCost = !line[15].equals("")?line[15].trim():null;
|
89 |
98 |
|
90 |
|
String secondPaymentAmount = !line[16].equals("")?line[16].trim():null;
|
91 |
|
String secondPaymentDate = !line[17].equals("")?line[17].trim():null;
|
92 |
|
String secondPaymentOtherCosts = !line[18].equals("")?line[18].trim():null;
|
93 |
|
String secondPaymentTransferCost = !line[19].equals("")?line[19].trim():null;
|
|
99 |
String secondPaymentAmount = !line[16].equals("")?line[16].trim():null;
|
|
100 |
String secondPaymentDate = !line[17].equals("")?line[17].trim():null;
|
|
101 |
String secondPaymentOtherCosts = !line[18].equals("")?line[18].trim():null;
|
|
102 |
String secondPaymentTransferCost = !line[19].equals("")?line[19].trim():null;
|
94 |
103 |
|
95 |
104 |
|
96 |
|
List<Object> orgs = organizationManager.search(organization);
|
97 |
|
if(orgs == null)
|
98 |
|
LOGGER.debug("Organization " + organization + " not exists!");
|
|
105 |
List<Object> orgs = organizationManager.search(organization);
|
|
106 |
if(orgs == null)
|
|
107 |
LOGGER.debug("Organization " + organization + " not exists!");
|
99 |
108 |
|
100 |
|
Organization org = (Organization) organizationManager.search(organization).get(0);
|
101 |
|
bid = this.initializeBid(funding_name,id,country,org,totalAmount,contractStartDate,contractEndDate);
|
102 |
|
LOGGER.debug("Bid initialized!");
|
|
109 |
Organization org = (Organization) organizationManager.search(organization).get(0);
|
|
110 |
bid = this.initializeBid(funding_name,id,country,org,totalAmount,contractStartDate,contractEndDate);
|
|
111 |
LOGGER.debug("Bid initialized!");
|
103 |
112 |
|
104 |
|
bid.setFirstInvoice(this.uploadInvoiceFile(path,folder_name,FIRST_INVOICE_PDF,
|
105 |
|
firstInvoiceDate,firstInvoiceNumber));
|
106 |
|
LOGGER.debug("First invoice ready!");
|
|
113 |
bid.setFirstInvoice(this.uploadInvoiceFile(path,folder_name,FIRST_INVOICE_PDF,
|
|
114 |
firstInvoiceDate,firstInvoiceNumber));
|
|
115 |
LOGGER.debug("First invoice ready!");
|
107 |
116 |
|
108 |
|
bid.setSecondInvoice(this.uploadInvoiceFile(path,folder_name,SECOND_INVOICE_PDF,
|
109 |
|
secondInvoiceDate,secondInvoiceNumber));
|
110 |
|
LOGGER.debug("Second invoice ready!");
|
|
117 |
bid.setSecondInvoice(this.uploadInvoiceFile(path,folder_name,SECOND_INVOICE_PDF,
|
|
118 |
secondInvoiceDate,secondInvoiceNumber));
|
|
119 |
LOGGER.debug("Second invoice ready!");
|
111 |
120 |
|
112 |
|
bid.setFirstPaymentDocument(this.uploadReceiptFile(path,folder_name,FIRST_PAYMENT_PDF,
|
113 |
|
firstPaymentAmount,firstPaymentDate,firstPaymentOtherCosts,firstPaymentTransferCost));
|
114 |
|
LOGGER.debug("First payment ready!");
|
|
121 |
bid.setFirstPaymentDocument(this.uploadReceiptFile(path,folder_name,FIRST_PAYMENT_PDF,
|
|
122 |
firstPaymentAmount,firstPaymentDate,firstPaymentOtherCosts,firstPaymentTransferCost));
|
|
123 |
LOGGER.debug("First payment ready!");
|
115 |
124 |
|
116 |
|
bid.setSecondPaymentDocument(this.uploadReceiptFile(path,folder_name,SECOND_PAYMENT_PDF,
|
117 |
|
secondPaymentAmount,secondPaymentDate,secondPaymentOtherCosts,secondPaymentTransferCost));
|
118 |
|
LOGGER.debug("Second payment ready!");
|
|
125 |
bid.setSecondPaymentDocument(this.uploadReceiptFile(path,folder_name,SECOND_PAYMENT_PDF,
|
|
126 |
secondPaymentAmount,secondPaymentDate,secondPaymentOtherCosts,secondPaymentTransferCost));
|
|
127 |
LOGGER.debug("Second payment ready!");
|
119 |
128 |
|
120 |
|
bid.setContract(this.uploadContract(path,folder_name,CONTRACT_PDF));
|
121 |
|
LOGGER.debug("Contract ready!");
|
122 |
|
alternativeFundingBidDao.save(bid);
|
|
129 |
bid.setContract(this.uploadContract(path,folder_name,CONTRACT_PDF));
|
|
130 |
LOGGER.debug("Contract ready!");
|
|
131 |
alternativeFundingBidDao.save(bid);
|
|
132 |
}
|
|
133 |
|
|
134 |
} catch (IOException | ParseException e) {
|
|
135 |
LOGGER.debug(e);
|
123 |
136 |
}
|
|
137 |
}
|
124 |
138 |
|
125 |
|
} catch (IOException | ParseException e) {
|
126 |
|
LOGGER.debug(e);
|
127 |
|
}
|
128 |
139 |
}
|
129 |
140 |
|
130 |
141 |
private eu.dnetlib.goldoa.domain.File uploadContract(String basePath, String folder_name, String contract) throws IOException {
|
1.Add init methods for debug purpose on funding bids / request
2.Add properties for pending mails / funding bids.