package pt.estgp.estgweb.services.sigesimports;
import jomm.dao.impl.AbstractDao;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.StaleStateException;
import pt.estgp.estgweb.Globals;
import pt.estgp.estgweb.domain.*;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.services.common.CommonServicesManager;
import pt.estgp.estgweb.services.email.SendEmailService;
import pt.estgp.estgweb.services.expceptions.ServiceException;
import pt.estgp.estgweb.services.jobs.ServiceJob;
import pt.estgp.estgweb.services.logresults.ILogMessages;
import pt.estgp.estgweb.services.logresults.LogMessageTypeEnum;
import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessage;
import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages;
import pt.estgp.estgweb.utils.ConfigProperties;
import pt.estgp.estgweb.utils.Email;
import pt.ipportalegre.siges.web.services.ArrayOfDecimal;
import pt.ipportalegre.siges.web.services.Disciplina;
import pt.ipportalegre.siges.web.services.Docente;
import pt.ipportalegre.siges.web.services.SiGesWEB;
import pt.utl.ist.berserk.logic.serviceManager.IService;
import javax.xml.namespace.QName;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
/**
* @author Jorge Machado
* @date 11/May/2008
* @time 12:51:32
* @see pt.estgp.estgweb
*/
public class ImportTeachersService
extends ServiceJob
implements IService
{
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(ImportTeachersService.
class);
private static final int MAX_COMMIT =
100;
//int studentsMerged = 0;
int teachersNew =
0;
int teachersZeroUnits =
0;
int unitsNotFound =
0;
int unitsAddedToTeachers =
0;
int unitsRemovedToTeachers =
0;
int unitsLocalAddedNotRemoved =
0;
int teachersFound =
0;
int teachersChangeBI =
0;
int unitsLocallyRemovedNotAdded =
0;
//todo meter a zero no run
public ILogMessages run
(1.5.0/docs/api/java/lang/String.html">String year
) throws ServiceException
{
teachersNew =
0;
teachersZeroUnits =
0;
unitsNotFound =
0;
unitsAddedToTeachers =
0;
unitsRemovedToTeachers =
0;
unitsLocalAddedNotRemoved =
0;
teachersFound =
0;
teachersChangeBI =
0;
unitsLocallyRemovedNotAdded =
0;
1.5.0/docs/api/java/lang/String.html">String msgS =
"STARTING TEACHERS IMPORT SERVICE FOR YEAR: " + year
;
serviceLogInfo
(msgS
);
logger.
info(msgS
);
DefaultLogMessages logMessages =
new DefaultLogMessages
();
logMessages.
addMessage(new DefaultLogMessage
("import.teachers", LogMessageTypeEnum.
INFO,
"instituicao " + DaoFactory.
getConfigurationDaoImpl().
getSigesInstitutionCode()));
try
{
1.5.0/docs/api/java/lang/String.html">String WSDL = DaoFactory.
getConfigurationDaoImpl().
getSigesWebServicesWsdl();
SiGesWEB service
;
try
{
serviceLogInfo
("STARTING WEB SERVICE AT " + WSDL
);
service =
new SiGesWEB
(new 1.5.0/docs/api/java/net/URL.html">URL(WSDL
),
new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName(Globals.
SIGES_WEBSERVICE_TARGET_NAMESPACE,
"SiGesWEB"));
}
catch (1.5.0/docs/api/java/net/MalformedURLException.html">MalformedURLException e
)
{
logMessages.
addMessage(new DefaultLogMessage
("import.error", e.
toString(),
"erro na configuracao do WEB Service", LogMessageTypeEnum.
INFO));
logger.
fatal(e, e
);
serviceLogFatal
(logMessages.
getLastMessage(), e
);
return logMessages
;
}
ArrayOfDecimal codigosDocentes = service.
getSiGesWEBSoap().
getCodigosDocentesInscritosDaInstituicao(new 1.5.0/docs/api/java/math/BigDecimal.html">BigDecimal(DaoFactory.
getConfigurationDaoImpl().
getSigesInstitutionCode()), year
);
List
<BigDecimal
> codigos = codigosDocentes.
getDecimal();
int i =
1;
for (1.5.0/docs/api/java/math/BigDecimal.html">BigDecimal c : codigos
)
{
teachersFound++
;
if (i++
> MAX_COMMIT
)
{
i =
0;
setProgress
((int) (((float)teachersFound
)/
((float)codigos.
size())*100.0f
));
AbstractDao.
getCurrentSession().
getTransaction().
commit();
AbstractDao.
getCurrentSession().
beginTransaction();
}
Docente d = service.
getSiGesWEBSoap().
getDocente(c,
new 1.5.0/docs/api/java/math/BigDecimal.html">BigDecimal(DaoFactory.
getConfigurationDaoImpl().
getSigesInstitutionCode()), year
);
logger.
info("Codigo Funcionario Importado: SIGES(" + d.
getCodigoFuncionario().
intValue() +
") email IPP SIGES: " + d.
getEmail());
logger.
info("SIGES IMPORTED INFO: " + docenteToString
(d
));
Teacher t = DaoFactory.
getTeacherDaoImpl().
loadBySigesCode(d.
getCodigoFuncionario().
intValue());
boolean newUser =
false;
if (t ==
null)
{
msgS =
"Teacher does not exist in baco, will create SIGES:" + d.
getCodigoFuncionario().
intValue();
logger.
info(msgS
);
serviceLogInfo
(msgS
);
t = DomainObjectFactory.
createTeacherImpl();
DaoFactory.
getTeacherDaoImpl().
save(t
);
newUser =
true;
teachersNew++
;
}
else
{
msgS =
"Teacher EXIST in baco with SIGES: " + d.
getCodigoFuncionario().
intValue();
logger.
info(msgS
);
//serviceLogInfo(msgS); //NOT NEED EXCESS OF INFORMATION
}
msgS =
"Will persist SIGES(" + d.
getCodigoFuncionario().
intValue() +
") baco (username:" + t.
getUsername() +
") baco name:" + t.
getName();
logger.
info(msgS
);
serviceLogInfo
(msgS
);
try
{
persist
(d, t, newUser,year
);
}
catch (1.5.0/docs/api/java/lang/Exception.html">Exception e
)
{
logger.
error(e, e
);
throw e
;
}
if (newUser
)
CommonServicesManager.
getInstance().
adviseNew(t
);
else
{
1.5.0/docs/api/java/lang/String.html">String password = t.
getPassword();
t.
setPassword(null);
CommonServicesManager.
getInstance().
adviseUpdate(t
);
t.
setPassword(password
);
}
}
}
catch(StaleStateException e
)
{
AbstractDao.
getCurrentSession().
getTransaction().
rollback();
AbstractDao.
getCurrentSession().
beginTransaction();
logger.
error(e,e
);
serviceLogError
("Rolling back will lost previous updates: " + e.
toString(),e
);
sendNotificationAdmin
("Erro de importacao de docentes",e.
toString());
}
catch(HibernateException e
)
{
AbstractDao.
getCurrentSession().
getTransaction().
rollback();
AbstractDao.
getCurrentSession().
beginTransaction();
logger.
error(e,e
);
serviceLogError
("Rolling back will lost previous updates: " + e.
toString(),e
);
sendNotificationAdmin
("Erro de base de dados importacao de docentes, provavelmente chave errada, corrigir no MySql",e.
toString());
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logMessages.
addMessage(new DefaultLogMessage
("import.error", e.
toString(),
"see log for details", LogMessageTypeEnum.
ERROR));
logger.
error(e, e
);
throw new ServiceException
(e.
toString(), e
);
}
serviceLogInfo
("############################");
serviceLogInfo
("############################");
serviceLogInfo
("#Teachers found: " + teachersFound
);
serviceLogInfo
("#Teachers New: " + teachersNew
);
serviceLogInfo
("#Teachers Zero Units: " + teachersZeroUnits
);
serviceLogInfo
("#Units not found: " + unitsNotFound
);
serviceLogInfo
("#Units removed to Teachers: " + unitsRemovedToTeachers
);
serviceLogInfo
("#Units added to Teachers: " + unitsAddedToTeachers
);
serviceLogInfo
("#Units not Removed because localy added: " + unitsLocalAddedNotRemoved
);
serviceLogInfo
("#Units not Added because localy removed: " + unitsLocallyRemovedNotAdded
);
if(teachersChangeBI
>0)
{
serviceLogInfo
("#>>>>>AVISO AVISO<<<<<<<<<: ");
serviceLogInfo
("#>>>>>AVISO AVISO<<<<<<<<<: ");
serviceLogInfo
("#>>>>>NUMEROS DE PROFESSORES MUDARAM DE BI<<<<<<<<<: CONSULTAR LOG");
serviceLogInfo
("#CODIGO SIGES COM BIs DIFERENTES:" + teachersChangeBI
);
}
setProgress
(100
);
logMessages.
addMessage(new DefaultLogMessage
("import.teachers.terminating", LogMessageTypeEnum.
INFO));
logger.
info("terminating teacher import");
serviceLogInfo
("terminating teacher import");
return logMessages
;
}
/**
* Envio de Notificação aos operadores do CI
* @param subject
* @param cause
*/
private void sendNotificationAdmin
(1.5.0/docs/api/java/lang/String.html">String subject,
1.5.0/docs/api/java/lang/String.html">String cause
)
{
//todo JOB
List
<String
> emails = ConfigProperties.
getListValues("admin.email");
for(1.5.0/docs/api/java/lang/String.html">String email:emails
)
{
serviceLogWarn
(">>>>>>>>ENVIANDO NOTIFICACAO A ADMINISTRACAO: " + email
);
logger.
warn(">>>>>>>>ENVIANDO NOTIFICACAO A ADMINISTRACAO: " + email
);
}
List
<String
> arguments =
new ArrayList
<String
>();
arguments.
add(cause.
replace("\n",
"<br/>"));
Email email =
new Email
(subject,emails,Globals.
SYSTEM_EMAIL_BOX,
"messageToAdmin_pt.txt",arguments
);
try {
new SendEmailService
().
sendEmail(email
);
} catch (ServiceException e
) {
e.
printStackTrace();
}
}
/**
* Implementação local do toString para a class Docente que foi gerada pelos web-services
* @param d
* @return
*/
public 1.5.0/docs/api/java/lang/String.html">String docenteToString
(Docente d
)
{
return "Docente{" +
"codigoFuncionario=" + d.
getCodigoFuncionario() +
", nomeFuncionario='" + d.
getNomeFuncionario() +
'\'' +
", nomeFuncionarioInt='" + d.
getNomeFuncionarioInt() +
'\'' +
", nomeAcademico='" + d.
getNomeAcademico() +
'\'' +
", sexo='" + d.
getSexo() +
'\'' +
", dataNascimento=" + d.
getDataNascimento() +
", morada='" + d.
getMorada() +
'\'' +
", codigoPostal=" + d.
getCodigoPostal() +
", subCodigoPostal=" + d.
getSubCodigoPostal() +
", email='" + d.
getEmail() +
'\'' +
", numeroBi='" + d.
getNumeroBi() +
'\'' +
", usernameNetpa='" + d.
getUsernameNetpa() +
'\'' +
", disciplinas=" + d.
getDisciplinas() +
'}';
}
private void cloneFields
(Docente teacherSiges, Teacher teacher
)
{
teacher.
setName(teacherSiges.
getNomeFuncionarioInt());
teacher.
setEmail(teacherSiges.
getEmail());
1.5.0/docs/api/java/lang/String.html">String msgS
;
if(teacherSiges.
getEmail() !=
null && teacherSiges.
getEmail().
endsWith(Globals.
EMAIL_LOCAL_SUFFIX))
{
int atIndex = teacherSiges.
getEmail().
indexOf("@");
if (atIndex
> 0
)
{
teacher.
setUsername(teacherSiges.
getEmail().
substring(0, atIndex
));
msgS =
"Teacher SIGES:" + teacherSiges.
getCodigoFuncionario().
intValue() +
" foi-lhe atribuido o username d" + teacherSiges.
getEmail().
substring(0, atIndex
);
logger.
info(msgS
);
serviceLogInfo
(msgS
);
}
else
{
msgS =
"Teacher SIGES:" + teacherSiges.
getCodigoFuncionario().
intValue() +
" NAO lhe foi atribuido username o email não tem o caracter @";
logger.
info(msgS
);
serviceLogInfo
(msgS
);
}
}
else
{
msgS =
"Teacher SIGES:" + teacherSiges.
getCodigoFuncionario().
intValue() +
" nao tem email no SIGES foi-lhe atribuido o username d" + teacherSiges.
getCodigoFuncionario().
intValue();
logger.
info(msgS
);
serviceLogInfo
(msgS
);
teacher.
setUsername("d" + teacherSiges.
getCodigoFuncionario().
intValue());
}
teacher.
setSigesCode(teacherSiges.
getCodigoFuncionario().
intValue());
teacher.
setAddress(teacherSiges.
getMorada());
teacher.
setZip("" + teacherSiges.
getCodigoPostal().
intValue());
teacher.
setBi(teacherSiges.
getNumeroBi());
teacher.
setEmployerName(teacherSiges.
getNomeFuncionario());
teacher.
setAcademicName(teacherSiges.
getNomeAcademico());
teacher.
setBirthDate(teacherSiges.
getDataNascimento().
toGregorianCalendar().
getTime());
}
/**
* Nao esta testado
* jm
*
* @param teacherSiges docente
* @param teacher teacher
* @throws Exception .
*/
private void persist
(Docente teacherSiges, Teacher teacher,
boolean newUser,
1.5.0/docs/api/java/lang/String.html">String year
) throws 1.5.0/docs/api/java/lang/Exception.html">Exception
{
1.5.0/docs/api/java/lang/String.html">String msgS
;
try
{
if(newUser
)
{
teachersNew++
;
cloneFields
(teacherSiges, teacher
);
serviceLogInfo
("NOVO PROFESSOR ENCONTRADO: siges:" + teacherSiges.
getCodigoFuncionario() +
" bi:" + teacher.
getBi() +
" nome:" + teacher.
getName());
}
//CASO EM QUE O DOCENTE NO SIGES FOI ATRIBUIDO A OUTRO ESTUDANTE PARA PREENCHER BURACO NA NUMERACAO
else if(teacherSiges.
getNumeroBi() ==
null || teacher.
getBi() ==
null ||
! teacherSiges.
getNumeroBi().
equals(teacher.
getBi()))
{
teachersChangeBI++
;
1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder builder =
new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder();
builder.
append("ATENCAO NUMERO DE PROFESSOR " + teacherSiges.
getCodigoFuncionario() +
" MUDOU DE DONO VAI SER BLOQUEADO IMEDIATAMENTE\n");
builder.
append("ALTERANDO DADOS DO PROFESSOR " + teacherSiges.
getCodigoFuncionario() +
"\n");
builder.
append("<<<<<<<ANTES: " +
"\n");
builder.
append("<<<<<<<BI: " + teacher.
getBi() +
"\n");
builder.
append("<<<<<<<Nome: " + teacher.
getName() +
"\n");
builder.
append("<<<<<<<Username: " + teacher.
getUserNameNetpa() +
"\n");
builder.
append("<<<<<<<Address: " + teacher.
getAddress() +
"\n");
builder.
append("<<<<<<<Zip: " + teacher.
getZip() +
"\n");
builder.
append("<<<<<<<Email: " + teacher.
getEmail() +
"\n");
builder.
append("<<<<<<<Phone: " + teacher.
getPhonenumber() +
"\n");
cloneFields
(teacherSiges, teacher
);
//teacher.setAutoBlockMode(false);
//teacher.setManualBlock(true);
builder.
append("DEPOIS: " +
"\n");
builder.
append("BI: " + teacher.
getBi() +
"\n");
builder.
append("Nome: " + teacher.
getName() +
"\n");
builder.
append("Username: " + teacher.
getUserNameNetpa() +
"\n");
builder.
append("Address: " + teacher.
getAddress() +
"\n");
builder.
append("Zip: " + teacher.
getZip() +
"\n");
builder.
append("Email: " + teacher.
getEmail() +
"\n");
builder.
append("Phone: " + teacher.
getPhonenumber() +
"\n");
serviceLogWarn
(builder.
toString());
sendNotificationAdmin
("CODIGO SIGES PROFESSOR " + teacherSiges.
getCodigoFuncionario() +
" MUDOU DE DONO - NAO FOI BLOQUEADO OS DADOS FORAM REPOSTOS ",builder.
toString());
}
else
{
//VAMOS APENAS ADICIONAR CAMPOS QUE AINDA NAO EXISTAM IGUAL AO CLONE MAS NAO MECHE
if(teacher.
getName() ==
null || teacher.
getName().
length() == 0
)
teacher.
setName(teacherSiges.
getNomeFuncionarioInt());
//Email instituicao
if(teacher.
getEmail() ==
null || teacher.
getEmail().
indexOf("@") < 0
)
teacher.
setEmail(teacherSiges.
getEmail());
if (teacherSiges.
getEmail() !=
null && (teacher.
getUsername() ==
null || teacher.
getUsername().
trim().
length() == 0
) && teacherSiges.
getEmail().
endsWith(Globals.
EMAIL_LOCAL_SUFFIX))
{
int atIndex = teacherSiges.
getEmail().
indexOf("@");
if (atIndex
> 0
)
{
teacher.
setUsername(teacherSiges.
getEmail().
substring(0, atIndex
));
msgS =
"Teacher SIGES:" + teacherSiges.
getCodigoFuncionario().
intValue() +
" foi-lhe atribuido o username d" + teacherSiges.
getEmail().
substring(0, atIndex
);
logger.
info(msgS
);
serviceLogInfo
(msgS
);
}
else
{
msgS =
"Teacher SIGES:" + teacherSiges.
getCodigoFuncionario().
intValue() +
" NAO lhe foi atribuido username o email não tem o caracter @";
logger.
info(msgS
);
serviceLogInfo
(msgS
);
}
}
else if(teacher.
getUsername() ==
null || teacher.
getUsername().
trim().
length() ==
0)
{
msgS =
"Teacher SIGES:" + teacherSiges.
getCodigoFuncionario().
intValue() +
" nao tem email no SIGES foi-lhe atribuido o username d" + teacherSiges.
getCodigoFuncionario().
intValue();
logger.
info(msgS
);
serviceLogInfo
(msgS
);
teacher.
setUsername("d" + teacherSiges.
getCodigoFuncionario().
intValue());
}
else
{
//ALL OK
//username não foi alterado
//msgS="Teacher SIGES:" + teacherSiges.getCodigoFuncionario().intValue() + " nao lhe foi alterado o username " + teacher.getUsername();
//logger.info(msgS);
//serviceLogInfo(msgS);
}
teacher.
setSigesCode(teacherSiges.
getCodigoFuncionario().
intValue());
if(teacher.
getAddress() ==
null || teacher.
getAddress().
length() == 0
)
teacher.
setAddress(teacherSiges.
getMorada());
if(teacher.
getZip() ==
null || teacher.
getZip().
length() ==
0)
teacher.
setZip("" + teacherSiges.
getCodigoPostal().
intValue());
if(teacher.
getBi() ==
null || teacher.
getBi().
length() == 0
)
teacher.
setBi(teacherSiges.
getNumeroBi());
teacher.
setEmployerName(teacherSiges.
getNomeFuncionario());
teacher.
setAcademicName(teacherSiges.
getNomeAcademico());
if(teacher.
getBirthDate() ==
null || teacher.
getBirthDate().
getTime() == 0
)
teacher.
setBirthDate(teacherSiges.
getDataNascimento().
toGregorianCalendar().
getTime());
}
//Desta forma as relacoes antigas sao ignoradas cria-se uma lista nova e atribui-se ao Teacher, o Hibernate faz resto e apaga as chaves estrangeiras antigas
if (teacherSiges.
getDisciplinas() ==
null || teacherSiges.
getDisciplinas().
getDisciplina() ==
null || teacherSiges.
getDisciplinas().
getDisciplina().
size() ==
0)
{
msgS =
"ATENTION TEACHER WITH ZERO UNITS: codigoFuncionario " + teacherSiges.
getCodigoFuncionario();
logger.
warn(msgS
);
serviceLogInfo
(msgS
);
}
else
{
//1 - PROCEDIMENTO CADEIRAS SAO CARREGADAS DO BACO DA LISTA QUE VEM DO SIGES -> units
//2 - Sao retiradas da lista units as que o teacher tem mas que foram removidas localmente
//3 - Sao adicionadas ao teacher as que o docente ainda nao tiver da lista units
//4 - Remover da lista do teacher as unidades que não vêm do SIGES e que não foram adicionadas localmente
//PASSO 1
Set
<CourseUnit
> units =
new HashSet
<CourseUnit
>();
for (Disciplina disciplina : teacherSiges.
getDisciplinas().
getDisciplina())
{
CourseUnit courseUnit = DaoFactory.
getCourseUnitDaoImpl().
loadBySigesCodeUnique("" + disciplina.
getCodigo(),
"" + disciplina.
getCodigoCurso(),
"" + disciplina.
getCdDuracao(),
"" + disciplina.
getCdLectivo());
if (courseUnit ==
null)
{
msgS =
"Unit not found: semestre:" + disciplina.
getCdDuracao() +
" codigo:" + disciplina.
getCodigo() +
" course:" + disciplina.
getCodigoCurso() +
" year:" + disciplina.
getCdLectivo();
logger.
warn(msgS
);
serviceLogWarn
(msgS
);
}
else
units.
add(courseUnit
);
}
//PASSO 2
Iterator
<CourseUnit
> iter = units.
iterator();
while (iter.
hasNext())
{
CourseUnit courseUnit = iter.
next();
//In case of a comming proxy
TeacherImpl tImpl =
(TeacherImpl
) DaoFactory.
getTeacherDaoImpl().
narrow(teacher
);
if (tImpl.
isLocalRemovedUnit(courseUnit
))
{
unitsLocallyRemovedNotAdded++
;
1.5.0/docs/api/java/lang/String.html">String msg =
"Removendo unidade: " +
((CourseUnitImpl
)courseUnit
).
getSigesUniqueIdentifiers() +
" - do professor: " + tImpl.
getSigesCode() +
" - Associacao existe no SIGES mas foi removido LOCALMENTE";
serviceLogInfo
(msg
);
logger.
info(msg
);
iter.
remove();
}
}
//PASSO 3
if (teacher.
getTeachedUnits() !=
null)
{
for (CourseUnit c : units
)
{
boolean isIn =
false;
for (CourseUnit tc : teacher.
getTeachedUnits())
{
if (tc.
equals(c
))
{
isIn =
true;
break;
}
}
if (!isIn
)
{
1.5.0/docs/api/java/lang/String.html">String msg =
"Adicionando unidade: " +
((CourseUnitImpl
)c
).
getSigesUniqueIdentifiers() +
" - ao teacher: " + teacher.
getSigesCode() +
" - Associacao nova no SIGES";
serviceLogInfo
(msg
);
logger.
info(msg
);
unitsAddedToTeachers++
;
teacher.
getTeachedUnits().
add(c
);
}
}
}
else
teacher.
setTeachedUnits(units
);
//PASSO 4 nao é feito nos teacher mas deveria ser
//PASSO 4
//Remover unidades deste ano que nao vem do SIGES e que nao foram adicionadas localmente
Iterator
<CourseUnit
> iterNowUnits = teacher.
getTeachedUnits().
iterator();
TeacherImpl tImpl =
(TeacherImpl
) DaoFactory.
getTeacherDaoImpl().
narrow(teacher
);
while(iterNowUnits.
hasNext())
{
CourseUnit cUNow = iterNowUnits.
next();
if(cUNow.
getImportYear().
equals(year
))
//Apenas tentamos apagar as unidades do ano corrente.
//Este servico trabalha com unidades importadas do ano que e passado como argumento
//Se importamos unidades desse ano, as dos outros anos nao vem na lista, logo
//iriamos constatar que nenhuma estava no SIGES o que nao e verdade.
//Assim so apagamos unidades do ano que estamos a importar e que nao venham
//na importacao desse ano
{
boolean added =
false;
for(CourseUnit c: units
)
{
if(cUNow.
equals(c
))
{
added =
true;
break;
}
}
if(!added
)
{
if(!tImpl.
isLocalRemovedUnit(cUNow
))
{
1.5.0/docs/api/java/lang/String.html">String msg =
"Removendo unidade: " +
((CourseUnitImpl
)cUNow
).
getSigesUniqueIdentifiers() +
" - do docente: " + teacher.
getSigesCode() +
" - Associacao desapareceu do SIGES";
serviceLogInfo
(msg
);
logger.
info(msg
);
iterNowUnits.
remove();
unitsRemovedToTeachers++
;
}
else
{
1.5.0/docs/api/java/lang/String.html">String msg =
"NAO REMOVIDA - Unidade: " +
((CourseUnitImpl
)cUNow
).
getSigesUniqueIdentifiers() +
" - do docente: " + teacher.
getSigesCode() +
" - Associacao desapareceu do SIGES mas foi adicionada localmente";
serviceLogInfo
(msg
);
logger.
info(msg
);
unitsLocalAddedNotRemoved++
;
}
}
}
}
}
}
catch (1.5.0/docs/api/java/lang/Exception.html">Exception e
)
{
logger.
error(e, e
);
List
<String
> emails =
new ArrayList
<String
>();
emails.
add(ConfigProperties.
getProperty("admin.email"));
List
<String
> arguments =
new ArrayList
<String
>();
1.5.0/docs/api/java/lang/String.html">String cause = e.
getCause() ==
null ? "" : e.
getCause().
toString();
arguments.
add((e.
toString() +
"\n" + cause
).
replace("\n",
"<br/>"));
Email email =
new Email
("Erro de importa��o de professores",emails,
"baco@estgp.pt",
"messageToAdmin_pt.txt",arguments
);
new SendEmailService
().
sendEmail(email
);
throw e
;
}
}
@
1.5.0/docs/api/java/lang/Override.html">Override
protected void runJobServiceTask
() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable {
1.5.0/docs/api/java/lang/String.html">String importYear =
(1.5.0/docs/api/java/lang/String.html">String) getParametersMap
().
get(JOB_importYear_KEY
).
getObject();
run
(importYear
);
}
public static final 1.5.0/docs/api/java/lang/String.html">String JOB_importYear_KEY =
"JOB_importYear_KEY";
/**
* Testar por aqui poi requer Super Role e assim e' autmatico
*
* @param args of main
* @throws ServiceException on error
*/
public static void main
(1.5.0/docs/api/java/lang/String.html">String[] args
) throws ServiceException
{
1.5.0/docs/api/java/lang/String.html">String year = DaoFactory.
getConfigurationDaoImpl().
getImportsDefaultImportYearCreateTransaction();
if(args
!=
null && args.
length > 0
)
year = args
[0
];
AbstractDao.
getCurrentSession().
beginTransaction();
new ImportTeachersService
().
run(year
);
AbstractDao.
getCurrentSession().
getTransaction().
commit();
}
}