package pt.estgp.estgweb.domain;
import org.apache.log4j.Logger;
import pt.estgp.estgweb.Globals;
import pt.estgp.estgweb.domain.utils.SimpleClearanceRuledSupport;
import pt.estgp.estgweb.utils.ConfigProperties;
import pt.estgp.estgweb.utils.DatesUtils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* Created by jorgemachado on 09/03/16.
*/
public class QuestionarioImpl
extends Questionario
implements ClearanceRuled
{
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(QuestionarioImpl.
class);
public enum 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State
{
CREATED
(1),
ASSIGNATION_DETAILS
(2),
ASSIGNING_ANSWERS_PROCESSEMENT
(3),
//NAO USADO NO PEDAGOGIGO OS ESTADOS INTERNOS RESOLVEM O PROBLEMA
ASSIGNED_ANSWERS
(4
),
PROCESSING
(5
),
PROCESSING_WITH_ANSWERS
(6
),
STOPED_WITH_ANSWERS
(6
),
CLOSED
(7
),
PROCESSING_OLAP
(8
),
OLAP
(9
);
private int pos =
1;
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State(int pos
)
{
this.
pos = pos
;
}
public static 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State parse
(1.5.0/docs/api/java/lang/String.html">String state
)
{
for(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State s:
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
values())
{
if(s.
name().
equals(state
))
return s
;
}
return CREATED
;
}
public int getPosition
()
{
return pos
;
}
}
//QuestionarioPedagogico SubState
public enum SubStatePedagogico
{
START
(1),
YEAR_SEMESTRE_ASSIGNED
(2),
ASSIGNING_COURSES
(3),
COURSES_ASSIGNED
(4),
//ESCOLHA DE CURSOS TERMINADA pode escolher tipologias e gerar respostas
ASSIGNING_ANSWERS
(5),
//ESCOLHA DE CURSOS TERMINADA pode escolher tipologias e gerar respostas
ANSWERS_ASSIGNED
(6),
//ESCOLHA DE CURSOS TERMINADA pode escolher tipologias e gerar respostas
FINNISHED_ANSWERS_GENERATING
(7
); //PODE SEMPRE VOLTAR A GERAR ANTES DE TERMINAR TEM DE SER INCREMENTAL
//Mas depois de clicar em Terminar muda para este estado terminado e já nao pode voltar a gerar respostas
private int pos =
1;
SubStatePedagogico
(int pos
)
{
this.
pos = pos
;
}
public static SubStatePedagogico parse
(1.5.0/docs/api/java/lang/String.html">String state
)
{
for(SubStatePedagogico s: SubStatePedagogico.
values())
{
if(s.
name().
equals(state
))
return s
;
}
return START
;
}
public int getPosition
()
{
return pos
;
}
}
public SubStatePedagogico getSubStatePedagodigoEnum
()
{
return SubStatePedagogico.
parse(getSubstate
());
}
public void setSubStatePedagogicoClass
(SubStatePedagogico subState
) {
setLogStates
(getLogStates
()+
"\n"+ DatesUtils.
getLogDateNow() +
" changing substate: " + getState
() +
" sub:(" + getSubstate
() +
") " +
" -> " + subState.
name());
setSubstate
(subState.
name());
}
public QuestionarioImpl
() {
super();
setStateClass
(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
CREATED);
1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat sdf =
new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat("MMMM yyyy",
new 1.5.0/docs/api/java/util/Locale.html">Locale("pt"));
1.5.0/docs/api/java/lang/String.html">String month = sdf.
format(new 5+0%2Fdocs%2Fapi+Date">Date());
1.5.0/docs/api/java/lang/String.html">String introHtml = ConfigProperties.
getProperty("questionario.intro.text");
1.5.0/docs/api/java/lang/String.html">String introWithMonth =
1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.
format(introHtml, month
);
setIntroHtml
(introWithMonth
);
setGroup1Title
(ConfigProperties.
getProperty("questionario.group1.title"));
setGroup2Title
(ConfigProperties.
getProperty("questionario.group2.title"));
setGroup3Title
(ConfigProperties.
getProperty("questionario.group3.title"));
setGroup4Title
(ConfigProperties.
getProperty("questionario.group4.title"));
setGroup5Title
(ConfigProperties.
getProperty("questionario.group5.title"));
setGroup6Title
(ConfigProperties.
getProperty("questionario.group6.title"));
setGroup7Title
(ConfigProperties.
getProperty("questionario.group7.title"));
setGroup8Title
(ConfigProperties.
getProperty("questionario.group8.title"));
setGroup9Title
(ConfigProperties.
getProperty("questionario.group9.title"));
setGroup10Title
(ConfigProperties.
getProperty("questionario.group10.title"));
setGroup1Code
(ConfigProperties.
getProperty("questionario.group1.code"));
setGroup2Code
(ConfigProperties.
getProperty("questionario.group2.code"));
setGroup3Code
(ConfigProperties.
getProperty("questionario.group3.code"));
setGroup4Code
(ConfigProperties.
getProperty("questionario.group4.code"));
setGroup5Code
(ConfigProperties.
getProperty("questionario.group5.code"));
setGroup6Code
(ConfigProperties.
getProperty("questionario.group6.code"));
setGroup7Code
(ConfigProperties.
getProperty("questionario.group7.code"));
setGroup8Code
(ConfigProperties.
getProperty("questionario.group8.code"));
setGroup9Code
(ConfigProperties.
getProperty("questionario.group9.code"));
setGroup10Code
(ConfigProperties.
getProperty("questionario.group10.code"));
for(int i =
1; i
<=
40;i++
)
{
try {
1.5.0/docs/api/java/lang/String.html">String group = ConfigProperties.
getProperty("questionario.p" + i +
".group");
1.5.0/docs/api/java/lang/reflect/Method.html">Method m =
this.
getClass().
getMethod("setP" + i +
"Group",
1.5.0/docs/api/java/lang/String.html">String.
class);
m.
invoke(this,group
);
1.5.0/docs/api/java/lang/String.html">String pergunta = ConfigProperties.
getProperty("questionario.p" + i
);
1.5.0/docs/api/java/lang/reflect/Method.html">Method m2 =
this.
getClass().
getMethod("setP" + i,
1.5.0/docs/api/java/lang/String.html">String.
class);
m2.
invoke(this,pergunta
);
} catch (1.5.0/docs/api/java/lang/NoSuchMethodException.html">NoSuchMethodException e
) {
e.
printStackTrace();
} catch (1.5.0/docs/api/java/lang/reflect/InvocationTargetException.html">InvocationTargetException e
) {
e.
printStackTrace();
} catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e
) {
e.
printStackTrace();
}
}
}
static List
<IAnswersProcessor
> answersProcessors =
null;
public IAnswersProcessor getiAnswersProcessorClass
()
{
if(getiAnswersProcessor
() !=
null)
{
try {
return (IAnswersProcessor
) 1.5.0/docs/api/java/lang/Class.html">Class.
forName(getiAnswersProcessor
()).
newInstance();
} catch (1.5.0/docs/api/java/lang/Exception.html">Exception e
) {
logger.
error(e,e
);
}
}
return new IAnswersProcessor
() {
@
1.5.0/docs/api/java/lang/Override.html">Override
public 1.5.0/docs/api/java/lang/String.html">String getHistoryDriveConstraint
() {
return null;
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public 1.5.0/docs/api/java/lang/String.html">String getTitle
() {
return "---";
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public 1.5.0/docs/api/java/lang/String.html">String getAfetacoesManagementForward
() {
return null;
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public void initQuestionarioAfetacoesVariables
(QuestionarioImpl questionario
) {
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public void startAfetacoes
(QuestionarioImpl questionario
) {
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public void initClearances
(QuestionarioImpl questionario, UserSessionImpl session, SimpleClearanceRuledSupport s
) {
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public 1.5.0/docs/api/java/lang/Class.html">Class getJobServiceTaskAnswersProcessor
() {
return null;
}
};
}
public static List
<IAnswersProcessor
> getIAnswerProcessors
()
{
if(answersProcessors ==
null)
{
answersProcessors =
new ArrayList
<IAnswersProcessor
>();
List
<String
> processors = ConfigProperties.
getListValues("pt.estgp.estgweb.domain.IAnswersProcessor.");
for(1.5.0/docs/api/java/lang/String.html">String p: processors
)
{
try {
IAnswersProcessor iAnswersProcessor =
(IAnswersProcessor
) 1.5.0/docs/api/java/lang/Class.html">Class.
forName(p
).
newInstance();
answersProcessors.
add(iAnswersProcessor
);
} catch (1.5.0/docs/api/java/lang/Exception.html">Exception e
) {
logger.
error(e, e
);
}
}
}
return answersProcessors
;
}
public static void main
(1.5.0/docs/api/java/lang/String.html">String[] args
)
{
QuestionarioImpl q =
new QuestionarioImpl
();
1.5.0/docs/api/java/lang/System.html">System.
out.
println(q
);
}
public 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State getStateEnum
()
{
return 1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
parse(getState
());
}
public void setStateClass
(1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State state
) {
setLogStates
(getLogStates
()+
"\n"+ DatesUtils.
getLogDateNow() +
" changing state: " + getState
() +
" -> " + state.
name());
setState
(state.
name());
}
/**CLEARANCES SUPPORT**/
SimpleClearanceRuledSupport clearanceRuledSupport =
null;
public SimpleClearanceRuledSupport getClearanceRuledSupport
() {
return clearanceRuledSupport
;
}
public void setClearanceRuledSupport
(SimpleClearanceRuledSupport clearanceRuledSupport
) {
this.
clearanceRuledSupport = clearanceRuledSupport
;
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public boolean isClearanceInitialized
(UserSessionImpl u
) {
return clearanceRuledSupport ==
null ? false :
clearanceRuledSupport.
isClearanceInitialized(u
);
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public boolean isClear
(UserSessionImpl u,
1.5.0/docs/api/java/lang/String.html">String OP
) {
if(clearanceRuledSupport ==
null)
return false;
return clearanceRuledSupport.
isClear(u, OP
);
}
@
1.5.0/docs/api/java/lang/Override.html">Override
public void initClearances
(UserSessionImpl usession,
boolean force
) {
SimpleClearanceRuledSupport s =
new SimpleClearanceRuledSupport
();
if((usession.
getUser().
isSuperuserOrAdmin()
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_ADMIN))
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_ASSIGNEMENTS_CHECK_STUDENTS_ADMIN)
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_TIPOLOGIAS_ADMIN)
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_ASSIGNEMENTS_CHECK_TEACHERS_ADMIN)
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_GERAIS))
{
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SEE_FORM.
name(),usession
);
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SEE_ADMIN.
name(),usession
);
if((usession.
getUser().
isSuperuserOrAdmin()
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_ADMIN)))
{
if(getStateEnum
() == QuestionarioImpl.
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
CREATED &&
getQuestionarioHistoryDrive
() !=
null &&
getiAnswersProcessorClass
() !=
null)
{
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SAVE_FORM.
name(),usession
);
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS.
name(),usession
);
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_DELETE.
name(),usession
);
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SAVE_ANSWER_PROCESSOR.
name(),usession
);
}
if(getStateEnum
() ==
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
ASSIGNED_ANSWERS)
{
s.
addClearance(QuestionarioClearancesOperation.
QUESTIONARIO_REVERT_TO_ASSIGNATION_DETAILS.
name(),usession
);
s.
addClearance(QuestionarioClearancesOperation.
QUESTIONARIO_START_PROCESSEMENT.
name(),usession
);
}
if(getStateEnum
() ==
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
PROCESSING)
{
s.
addClearance(QuestionarioClearancesOperation.
QUESTIONARIO_STOP_PROCESSEMENT.
name(),usession
);
}
if(getStateEnum
() ==
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
PROCESSING_WITH_ANSWERS)
{
s.
addClearance(QuestionarioClearancesOperation.
QUESTIONARIO_STOP_PROCESSEMENT.
name(),usession
);
}
if(getStateEnum
() ==
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
STOPED_WITH_ANSWERS)
{
s.
addClearance(QuestionarioClearancesOperation.
QUESTIONARIO_START_PROCESSEMENT.
name(),usession
);
}
if(getStateEnum
() == QuestionarioImpl.
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
ASSIGNATION_DETAILS)
{
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SAVE_FORM.
name(),usession
);
}
}
//ANO SEMESTRE ESPECIFICO apenas neste estado, em atribuição de respostas e respostas atribuidas já não permite
if(getStateEnum
() == QuestionarioImpl.
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
ASSIGNATION_DETAILS)
{
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_ASSIGNATION_OPERATIONS.
name(),usession
);
}
if(getStateEnum
() == QuestionarioImpl.
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
STOPED_WITH_ANSWERS || getStateEnum
() == QuestionarioImpl.
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
PROCESSING || getStateEnum
() == QuestionarioImpl.
1.5.0/docs/api/org/omg/PortableServer/POAManagerPackage/State.html">State.
PROCESSING_WITH_ANSWERS)
{
if(usession.
getUser().
isSuperuserOrAdmin()
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_ADMIN)
|| usession.
getUser().
hasRole(Globals.
QUESTIONARIOS_GERAIS))
{
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SEE_DASHBOARD.
name(),usession
);
s.
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SEE_FORM.
name(),usession
);
}
}
}
//AS CLEARANCES SAO VERIFICADAS LA DENTRO PARA TODOS OS ESTADOS
getiAnswersProcessorClass
().
initClearances(this,usession,s
);
setClearanceRuledSupport
(s
);
}
public static enum QuestionarioClearancesOperation
{
QUESTIONARIO_NEW_FORM,
QUESTIONARIO_SAVE_FORM,
QUESTIONARIO_SEE_FORM,
QUESTIONARIO_SEE_ADMIN,
QUESTIONARIO_SAVE_ANSWER_PROCESSOR,
QUESTIONARIO_SET_STATE_ASSIGNATION_DETAILS,
QUESTIONARIO_ASSIGNATION_OPERATIONS,
QUESTIONARIO_DELETE,
QUESTIONARIO_REVERT_ALL_ASSIGNEMENTS,
QUESTIONARIO_PUT_ANSWERS_ASSIGNED,
QUESTIONARIO_REVERT_TO_ASSIGNATION_DETAILS,
QUESTIONARIO_START_PROCESSEMENT,
QUESTIONARIO_STOP_PROCESSEMENT,
/*Pedagogico Cursos*/
QUESTIONARIO_SET_ANO_SEMESTRE,
QUESTIONARIO_SCHEDULLE_SELECT_COURSES,
QUESTIONARIO_SCHEDULLE_SEE_SELECT_COURSES,
QUESTIONARIO_CHANGE_TIPOLOGIES,
QUESTIONARIO_START_ASSIGN_ANSWERS,
QUESTIONARIO_SEE_START_ASSIGN_ANSWERS,
QUESTIONARIO_CHANGE_ASSIGNEMENTS,
QUESTIONARIO_CHANGE_ASSIGNEMENTS_CHECK_TEACHERS,
QUESTIONARIO_CHANGE_ASSIGNEMENTS_USE_UNIT,
QUESTIONARIO_SEE_DASHBOARD
;
public static QuestionarioClearancesOperation parse
(1.5.0/docs/api/java/lang/String.html">String clearance
)
{
if(clearance ==
null)
return null;
for(QuestionarioClearancesOperation op: QuestionarioClearancesOperation.
values())
{
if(op.
name().
equals(clearance
))
return op
;
}
return null;
}
}
1.5.0/docs/api/java/lang/String.html">String[] afetacoesVarCoursesSelectionForJob
;
/**
* Variaveis especificas do modulo do pedagogico
* ver o PedagogicoAlunosProcessor que implementa o IAnswersProcessor
* que as inicia
*
* @return lista de cursos ids no BACO selecionados na tarefa
*/
public 1.5.0/docs/api/java/lang/String.html">String[] getAfetacoesVarCoursesSelectionForJob
() {
return afetacoesVarCoursesSelectionForJob
;
}
public void setAfetacoesVarCoursesSelectionForJob
(1.5.0/docs/api/java/lang/String.html">String[] afetacoesVarCoursesSelectionForJob
) {
this.
afetacoesVarCoursesSelectionForJob = afetacoesVarCoursesSelectionForJob
;
}
}