Subversion Repositories bacoAlunos

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.services.courses;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import pt.estgp.estgweb.Globals;
import pt.estgp.estgweb.domain.CourseUnit;
import pt.estgp.estgweb.services.ftpservices.FtpService;
import pt.estgp.estgweb.web.FtpServer;

import java.io.IOException;
import java.util.Date;

/**
 * Created by jorgemachado on 13/04/16.
 */

public class FtpFilesFacade implements IFilesServiceFacade {

    private static 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(FtpFilesFacade.class);
    FtpServer server;
    FtpServer.FtpClientWrapper client;

    1.5.0/docs/api/java/lang/String.html">String username = Globals.FTP_IONLINE_USER;
    1.5.0/docs/api/java/lang/String.html">String password = Globals.FTP_IONLINE_PASS;
    1.5.0/docs/api/java/lang/String.html">String url = Globals.FTP_IONLINE_URL;
    1.5.0/docs/api/java/lang/String.html">String startPath = Globals.FTP_IONLINE_START_PATH;
    CourseUnit cu = null;

    long[] contentsInfo = null;
    long[] dtpPlan = null;
    long[] dtpFicha = null;
    long[] dtpAvalEnu = null;
    long[] dtpAvalNotas = null;
    long[] dtpInquer = null;
    long[] dtpRelato = null;
    long[] dtpSums = null;

    public FtpFilesFacade() throws 1.5.0/docs/api/java/io/IOException.html">IOException
    {
        server = FtpServer.getNewServer(url, username, password);
        client = new FtpServer.FtpClientWrapper(server,3);
        client.setBufferSize(1024 * 1024);
        logger.info("BUFFER SIZE" + client.getBufferSize());
        client.enterLocalActiveMode();



    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public void reset(CourseUnit cu) throws 1.5.0/docs/api/java/io/IOException.html">IOException
    {
        /*
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        this.cu = cu;
        contentsInfo = null;
        dtpPlan = null;
        dtpFicha = null;
        dtpAvalEnu = null;
        dtpAvalNotas = null;
        dtpInquer = null;
        dtpRelato = null;
        dtpSums = null;
        /*try{
            client.quit();
            client.disconnect();
        }catch(Throwable e)
        { logger.error(e,e);}
        client = server.getClient();*/

    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public void close() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        client.close();
    }


    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getContentsNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException
    {
        if(contentsInfo == null)
            contentsInfo = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_CONTENTS,"");
        return contentsInfo[1];

    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getContentsNumberOfFolders() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(contentsInfo == null)
            contentsInfo = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_CONTENTS,"");
        return contentsInfo[0];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getContentsSize() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(contentsInfo == null)
            contentsInfo = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_CONTENTS,"");
        return contentsInfo[2];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getContentsLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(contentsInfo == null)
            contentsInfo = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_CONTENTS,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(contentsInfo[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getDtpPlaneamentoNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpPlan == null)
            dtpPlan = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Planeamento,"");
        return dtpPlan[1];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getDtpInqueritoPedagogicoNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpInquer == null)
            dtpInquer = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_InqueritoPedagogico,"");
        return dtpInquer[1];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getDtpAvaliacaoEnunciadosNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpAvalEnu == null)
            dtpAvalEnu = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Avaliacao + "/" + Globals.INTRANET_DTP_Avaliacao_enunciados ,"");
        return dtpAvalEnu[1];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getDtpAvaliacaoNotasNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpAvalNotas == null)
            dtpAvalNotas = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Avaliacao + "/" + Globals.INTRANET_DTP_Avaliacao_pautas ,"");
        return dtpAvalNotas[1];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getDtpFichaCurricularNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpFicha == null)
            dtpFicha = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_FichaCurricular ,"");
        return dtpFicha[1];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public long getDtpRelatorioAvaliacaoNumberOfFiles() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpRelato == null)
            dtpRelato = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_FichaAvaliacao,"");
        return dtpRelato[1];
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getDtpPlaneamentoLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpPlan == null)
            dtpPlan = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Planeamento,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(dtpPlan[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getDtpInqueritoPedagogicoLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpInquer == null)
            dtpInquer = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_InqueritoPedagogico,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(dtpInquer[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getDtpAvaliacaoEnunciadosLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpAvalEnu == null)
            dtpAvalEnu = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Avaliacao + "/" + Globals.INTRANET_DTP_Avaliacao_enunciados ,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(dtpAvalEnu[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getDtpAvaliacaoNotasLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpAvalNotas == null)
            dtpAvalNotas = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Avaliacao + "/" + Globals.INTRANET_DTP_Avaliacao_pautas ,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(dtpAvalNotas[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getDtpFichaCurricularLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpFicha == null)
            dtpFicha = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_FichaCurricular ,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(dtpFicha[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 5+0%2Fdocs%2Fapi+Date">Date getDtpRelatorioAvaliacaoLastUpdate() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        if(dtpRelato == null)
            dtpRelato = FtpService.calculateDirectoryInfo(client,startPath +  cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_FichaAvaliacao,"");
        return new 5+0%2Fdocs%2Fapi+Date">Date(dtpRelato[3]);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public JSONArray getAllFilesJsonFields() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
        return FtpService.getDirectoryFilesFields(client,startPath +  cu.getPathIntranet(),"");
    }
}