Subversion Repositories bacoAlunos

Rev

Rev 1306 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 jmachado 1
package pt.estgp.estgweb.services.courseunits;
2
 
3
import pt.utl.ist.berserk.logic.serviceManager.IService;
4
import pt.estgp.estgweb.domain.UserSession;
5
import pt.estgp.estgweb.domain.Course;
6
import pt.estgp.estgweb.domain.CourseUnit;
7
import pt.estgp.estgweb.domain.Teacher;
8
import pt.estgp.estgweb.domain.dao.DaoFactory;
9
import pt.estgp.estgweb.services.expceptions.ServiceException;
10
import pt.estgp.estgweb.utils.DatesUtils;
11
import pt.estgp.estgweb.Globals;
12
import org.apache.log4j.Logger;
13
import jomm.utils.BytesUtils;
14
import jomm.utils.StringsUtils;
15
import jomm.utils.FilesUtils;
16
import jomm.dao.impl.AbstractDao;
17
 
18
import java.io.File;
19
import java.io.FileWriter;
20
import java.io.IOException;
21
import java.util.List;
22
 
23
/*
24
 * @author Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt
25
 *
26
 *
27
 * Created at 17/Out/2003 , 23:45:24
28
 *
29
 */
30
/**
31
 * @author Jorge Machado
32
 *
33
 *
34
 * Created at 17/Out/2003 , 23:45:24
35
 *
36
 */
37
public class ScheduleCourseUnitAnnouncementSmsService implements IService
38
{
39
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(ScheduleCourseUnitAnnouncementSmsService.class);
40
 
41
    public 1.5.0/docs/api/java/lang/String.html">String run(1.5.0/docs/api/java/lang/String.html">String importYear, UserSession userSession) throws ServiceException
42
    {
43
        if(importYear == null || importYear.trim().length() == 0)
995 jmachado 44
            importYear = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear();
227 jmachado 45
        1.5.0/docs/api/java/lang/String.html">String importYearIntranet = DatesUtils.getImportYearIntranet();
46
        1.5.0/docs/api/java/lang/String.html">String tmpName =  BytesUtils.generateHexKey();
47
        1.5.0/docs/api/java/lang/String.html">String tmpDir = Globals.TMP_DIR + "/" + tmpName;
48
        new 1.5.0/docs/api/java/io/File.html">File(tmpDir).mkdirs();
49
        List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(importYear);
50
        try
51
        {
52
            1.5.0/docs/api/java/io/FileWriter.html">FileWriter batRunner = new 1.5.0/docs/api/java/io/FileWriter.html">FileWriter(tmpDir + "/create.bat");
53
 
54
            1.5.0/docs/api/java/lang/String.html">String back = "";
55
            for(Course c: courses)
56
            {
57
                1.5.0/docs/api/java/lang/String.html">String couseDirPath = tmpDir + "/" + StringsUtils.normalizeResourceName(c.getName()) + '.' + c.getCode();
58
                1.5.0/docs/api/java/io/File.html">File courseDir = new 1.5.0/docs/api/java/io/File.html">File(couseDirPath);
59
                courseDir.mkdirs();
60
                try
61
                {
62
                    1.5.0/docs/api/java/lang/String.html">String courseImportYearPathDos = couseDirPath + "\\" + importYearIntranet;
63
                    1.5.0/docs/api/java/lang/String.html">String courseImportYearPath = couseDirPath + "/" + importYearIntranet;
64
                    1.5.0/docs/api/java/io/File.html">File courseImportYearDir = new 1.5.0/docs/api/java/io/File.html">File(courseImportYearPath);
65
                    courseImportYearDir.mkdirs();
66
                    new 1.5.0/docs/api/java/io/File.html">File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1).mkdirs();
67
                    new 1.5.0/docs/api/java/io/File.html">File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2).mkdirs();
728 jmachado 68
                    new 1.5.0/docs/api/java/io/File.html">File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A).mkdirs();
227 jmachado 69
                    FilesUtils.copy(ScheduleCourseUnitAnnouncementSmsService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1 + "/" + Globals.INTRANET_SETUP_FILE_NAME);
70
                    FilesUtils.copy(ScheduleCourseUnitAnnouncementSmsService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2 + "/" + Globals.INTRANET_SETUP_FILE_NAME);
728 jmachado 71
                    FilesUtils.copy(ScheduleCourseUnitAnnouncementSmsService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A + "/" + Globals.INTRANET_SETUP_FILE_NAME);
227 jmachado 72
 
73
                    1.5.0/docs/api/java/lang/String.html">String callPathS1 = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_S1 + "\\").substring(tmpDir.length() + 1);
74
                    1.5.0/docs/api/java/lang/String.html">String callPathS2 = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_S2 + "\\").substring(tmpDir.length() + 1);
728 jmachado 75
                    1.5.0/docs/api/java/lang/String.html">String callPathA = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_A + "\\").substring(tmpDir.length() + 1);
227 jmachado 76
                    batRunner.write("cd " + back + callPathS1);
77
                    back = "..\\..\\..\\";
78
                    batRunner.write("\n");
79
                    batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
80
                    batRunner.write("\n");
81
                    batRunner.write("cd " + back + callPathS2);
82
                    batRunner.write("\n");
83
                    batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
84
                    batRunner.write("\n");
728 jmachado 85
                    batRunner.write("cd " + back + callPathA);
86
                    batRunner.write("\n");
87
                    batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
88
                    batRunner.write("\n");
227 jmachado 89
                    1.5.0/docs/api/java/io/FileWriter.html">FileWriter confWriterSemestre1 = new 1.5.0/docs/api/java/io/FileWriter.html">FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1 + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
90
                    1.5.0/docs/api/java/io/FileWriter.html">FileWriter confWriterSemestre2 = new 1.5.0/docs/api/java/io/FileWriter.html">FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2 + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
728 jmachado 91
                    1.5.0/docs/api/java/io/FileWriter.html">FileWriter confWriterA = new 1.5.0/docs/api/java/io/FileWriter.html">FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
227 jmachado 92
 
93
 
94
                    List<CourseUnit> courseUnits = DaoFactory.getCourseUnitDaoImpl().loadByCourse(c.getId(),importYear);
95
                    for(CourseUnit courseUnit: courseUnits)
96
                    {
97
                        1.5.0/docs/api/java/io/FileWriter.html">FileWriter nowWriter;
98
                        1.5.0/docs/api/java/lang/String.html">String semestre;
99
                        if(courseUnit.getSemestre().equals("S1"))
100
                        {
101
                            nowWriter = confWriterSemestre1;
102
                            semestre = Globals.INTRANET_SEMESTRE_S1;
103
                        }
728 jmachado 104
                        else if(courseUnit.getSemestre().equals("S2"))
227 jmachado 105
                        {
106
                            nowWriter = confWriterSemestre2;
107
                            semestre = Globals.INTRANET_SEMESTRE_S2;
108
                        }
728 jmachado 109
                        else
110
                        {
111
                            nowWriter = confWriterA;
112
                            semestre = Globals.INTRANET_SEMESTRE_A;
113
                        }
227 jmachado 114
 
115
                        1.5.0/docs/api/java/lang/String.html">String normalizedName = StringsUtils.normalizeResourceName(courseUnit.getName());
116
                        1.5.0/docs/api/java/lang/String.html">String unitPath = courseImportYearPath + "/" + semestre + "/" + normalizedName;
117
                        courseUnit.setNormalizedName(normalizedName);
118
                        courseUnit.setPathIntranet(unitPath.substring(tmpDir.length()));
119
                        nowWriter.write(normalizedName);
120
 
121
                        if(courseUnit.getTeachers() != null)
122
                        {
123
                            1.5.0/docs/api/java/lang/String.html">String users = "";
124
                            int counter = 0;
125
                            for(Teacher t: courseUnit.getTeachers())
126
                            {
127
                                if(t.getUsername() != null)
128
                                {
129
                                    users += " " + t.getUsername();
130
                                    counter++;
131
                                }
132
                            }
133
                            nowWriter.write(" " + counter + users);
134
                            nowWriter.write("\n");
135
                        }
136
                    }
137
                    confWriterSemestre1.close();
138
                    confWriterSemestre2.close();
139
                }
140
                catch (1.5.0/docs/api/java/io/IOException.html">IOException e)
141
                {
142
                    logger.error(e,e);
143
                }
144
            }
145
            batRunner.write("cd " + back);
146
            batRunner.close();
147
            FilesUtils.zipFolder(tmpDir,tmpDir + ".zip");
148
            FilesUtils.delete(tmpDir);
149
            return tmpName + ".zip";
150
        }
151
        catch (1.5.0/docs/api/java/io/IOException.html">IOException e)
152
        {
153
            logger.error(e,e);
154
        }
155
        return null;
156
    }
157
 
158
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException
159
    {
160
        AbstractDao.getCurrentSession().beginTransaction();
161
        new ScheduleCourseUnitAnnouncementSmsService().run(null,null);
162
        AbstractDao.getCurrentSession().getTransaction().commit();
163
    }
164
 
165
 
166
}