14,6 → 14,7 |
import pt.estgp.estgweb.domain.dao.impl.CourseUnitDaoImpl; |
import pt.estgp.estgweb.domain.views.CourseUnitProgramView; |
import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
import pt.estgp.estgweb.services.data.IRepositoryFile; |
import pt.estgp.estgweb.services.data.RepositoryService; |
import pt.estgp.estgweb.services.expceptions.ServiceException; |
import pt.estgp.estgweb.utils.DatesUtils; |
24,10 → 25,7 |
|
import javax.xml.transform.TransformerException; |
import javax.xml.transform.dom.DOMSource; |
import java.io.File; |
import java.io.FileInputStream; |
import java.io.FileOutputStream; |
import java.io.IOException; |
import java.io.*; |
import java.text.SimpleDateFormat; |
import java.util.*; |
|
171,22 → 169,49 |
} |
|
|
public boolean sendCurrentPdf2IonlineDontGeneratePdf(CourseUnit cu, List<String> errors,UserSession u,FTPClient client,List<String> warns) throws IOException, TransformerException, FOPException { |
|
if(cu.getProgramStreamId() != null && cu.getProgramStreamId().length()> 0) |
{ |
try |
{ |
IRepositoryFile repoFileLastVersion = repositoryService.load(cu.getProgramStreamId(), null); |
|
sendPdfFtpIonline(cu, errors, u, repoFileLastVersion.getInput(), repoFileLastVersion.getSaveDate(), client, warns); |
return true; |
} |
catch(Throwable e) |
{ |
logger.error("Loading repository file: " + cu.getProgramStreamId() + " " + e.toString(),e); |
} |
} |
return false; |
} |
|
|
public boolean sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u, FTPClient client, List<String> warns) throws IOException, TransformerException, FOPException |
{ |
RepositoryService repositoryService = new RepositoryService(); |
if(cu.getProgramStreamId() != null && cu.getProgramStreamId().length()> 0) |
{ |
RepositoryFileImpl repoFile = repositoryService.loadView(cu.getProgramStreamId()); |
String path = generatePdfFile(cu, errors, u); |
sendPdfFtpIonline(cu,errors,u,path,repoFile.getLastVersion().getSaveDate(),client,warns); |
return true; |
try |
{ |
RepositoryFileImpl repoFile = repositoryService.loadView(cu.getProgramStreamId()); |
String path = generatePdfFile(cu, errors, u); |
sendPdfFtpIonline(cu,errors,u,path,repoFile.getLastVersion().getSaveDate(),client,warns); |
return true; |
} |
catch(Throwable e) |
{ |
logger.error("Loading repository file: " + cu.getProgramStreamId() + " " + e.toString(),e); |
} |
} |
return false; |
} |
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd.HH_mm_ss"); |
|
private void sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u,String pdfPath,Date versionDate,FTPClient client,List<String> warnings) throws IOException, TransformerException, FOPException { |
private void sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u,InputStream pdfPath,Date versionDate,FTPClient client,List<String> warnings) throws IOException, TransformerException, FOPException { |
|
if(Globals.TEST_ENVIRONEMENT) |
{ |
218,7 → 243,7 |
} |
else |
{ |
if(!client.storeFile(cu.getCode() + "_" + cu.getNormalizedName() + "_v" + sdf.format(versionDate) + ".pdf",new FileInputStream(pdfPath))) |
if(!client.storeFile(cu.getCode() + "_" + cu.getNormalizedName() + "_v" + sdf.format(versionDate) + ".pdf",pdfPath)) |
{ |
errors.add("CANT store file in given time, probably timeout at " + Globals.FTP_DATA_STORE_TIMEOUT_SECONDS); |
} |
232,6 → 257,12 |
// |
} |
|
private void sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u,String pdfPath,Date versionDate,FTPClient client,List<String> warnings) throws IOException, TransformerException, FOPException { |
|
sendPdfFtpIonline(cu,errors,u,new FileInputStream(pdfPath),versionDate,client,warnings); |
// |
} |
|
private String generatePdfFile(CourseUnit cu, List<String> errors, UserSession u) throws TransformerException, IOException, FOPException { |
|
CourseUnitProgramImpl cProgram = (CourseUnitProgramImpl) DaoFactory.getCourseUnitProgramDaoImpl().narrow(cu.getCourseUnitProgram()); |
436,7 → 467,7 |
} |
|
|
public void storeAllPrograms() throws IOException { |
public void storeAllPrograms(boolean generate) throws IOException { |
CourseUnitDaoImpl dao = DaoFactory.getCourseUnitDaoImpl(); |
Query q = AbstractDao.getCurrentSession().createQuery("select c from c in class " + CourseUnit.class.getName() + " where c.importYear = ?"); |
q.setString(0,DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
455,7 → 486,10 |
try { |
List<String> errors = new ArrayList<String>(); |
System.out.print("Sending " + next.getCourse().getName() + " - " + next.getSemestre() + " - " + next.getNormalizedName()); |
if(sendPdfFtpIonline(next,errors,null,client,null)) |
boolean result = generate ? |
sendPdfFtpIonline(next, errors,null,client,null) : sendCurrentPdf2IonlineDontGeneratePdf(next, errors, null, client, null); |
|
if(result) |
System.out.print(" ... OK"); |
else |
System.out.print(" ... FAIL probably no StreamID"); |
469,12 → 503,17 |
logger.error(e, e); |
} catch (FOPException e) { |
e.printStackTrace(); |
}catch (Throwable e) { |
e.printStackTrace(); |
} |
|
AbstractDao.getCurrentSession().evict(next); |
logger.info(next.getName() + " done"); |
} |
logger.info("Service Done"); |
client.quit(); |
client.disconnect(); |
logger.info("Disconnecting FTP Client"); |
|
} |
|
482,7 → 521,8 |
public static void main(String[] args) throws IOException { |
|
AbstractDao.getCurrentSession().beginTransaction(); |
new SaveCourseUnitProgram().storeAllPrograms(); |
new SaveCourseUnitProgram().storeAllPrograms(false); |
logger.info("Flushing Database"); |
AbstractDao.getCurrentSession().flush(); |
AbstractDao.getCurrentSession().getTransaction().commit(); |
} |