Retrieve a user's id and keep it as long as the session is active in jsf - session

I have a web application in jsf where I would retrieve the id of the user for reuse in other managedbeans.
Each user has a session that is created as soon as it is autehtification the data are stored in a Mysql DB. I would like to retrieve and keep the id of the user store as long as the session is active. Can you help me please?
this are my managedBean
#ManagedBean
#SessionScoped
public class ProfManagedBeans {
private int idp;
private String email, pwd;
public HttpSession hs;
public ProfManagedBeans() {
}
public int getIdp() {
return idp;
}
public void setIdp(int id) {
this.idp = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public static PreparedStatement pstmt=null;
public static ResultSet rs = null;
public String query="";
public int dbid;
public String dbemail, dbpwd;
public String getDbemail() {
return dbemail;
}
public String getDbpwd() {
return dbpwd;
}
public void dbData(String uEmail){
DbConnect.getConnection();
query = "SELECT * FROM professeur where email='" + uEmail +"'";
try {
pstmt = DbConnect.conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
dbid = rs.getInt("id_pr");
dbemail = rs.getString("email");
dbpwd = rs.getString("pwd");
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println("Exception " + e);
}
}
public int getIdProf(){
dbData(email);
String ids = hs.getId();
if(ids == hs.getId()){
idp = dbid;
return idp;
}
return 0;
}
public String login(){
dbData(email);
if (email.equals(dbemail)==true&&pwd.equals(dbpwd)==true) {
hs = Util.getSession();
hs.setAttribute("email", dbemail);
System.out.println(hs.getId());
System.out.println(getIdProf());
return "success.xhtml";
}
else {
FacesMessage fm = new FacesMessage("Email error", "ERROR MSG");
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, fm);
return "LoginProf.xhtml";
}
}
public String logout() {
hs.invalidate();
return "/LoginProf.xhtml";
}
}
public class QuestionManagedBeans {
private int id,id_pr;
private String nomDesc, question, type;
private String reponse;
private double noteV, noteF;
private String niveau, matiere,chapitre, explication;
public static PreparedStatement pstmt=null;
public static ResultSet rs = null;
public String query="";
private ArrayList<Niveau> list ;
public QuestionManagedBeans() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNomDesc() {
return nomDesc;
}
public void setNomDesc(String nomDesc) {
this.nomDesc = nomDesc;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getReponse() {
return reponse;
}
public void setReponse(String reponse) {
this.reponse = reponse;
}
public double getNoteV() {
return noteV;
}
public void setNoteV(double noteV) {
this.noteV = noteV;
}
public double getNoteF() {
return noteF;
}
public void setNoteF(double noteF) {
this.noteF = noteF;
}
public String getNiveau() {
return niveau;
}
public void setNiveau(String niveau) {
this.niveau = niveau;
}
public String getMatiere() {
return matiere;
}
public void setMatiere(String matiere) {
this.matiere = matiere;
}
public String getExplication() {
return explication;
}
public String getChapitre() {
return chapitre;
}
public void setChapitre(String chapitre) {
this.chapitre = chapitre;
}
public void setExplication(String explication) {
this.explication = explication;
}
public int getId_pr() {
return id_pr;
}
public void setId_pr() {
ProfManagedBeans p = new ProfManagedBeans();
this.id_pr = p.getIdProf();
}
public boolean insertQuestion() throws SQLException {
Question q = new Question(id,nomDesc, question, type,reponse,noteV, noteF,niveau, matiere, chapitre ,explication,id_pr);
setNomDesc("");
setQuestion("");
setType("");
setReponse("");
setNoteV(0.0);
setNoteF(0.0);
setNiveau("");
setMatiere("");
setChapitre("");
setExplication("");
return new InsertDao().insertQuestionTF(q);
}
}
I want to recover the id of the proffessor as soon as it is authenticated to be able to add it to the question table
In InsertDao.java
public boolean insertQuestionTF(Question qu) throws SQLException{
DbConnect.getConnection();
ProfManagedBeans p = new ProfManagedBeans();
query ="INSERT INTO `question_tf` (`nomdesc`, `question`, `type`, `reponse`, `noteV`, `noteF`, `niveau`, `matiere`, `chapitre`, `explication`, `id_pr`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
pstmt = DbConnect.conn.prepareStatement(query);
pstmt.setString(1, qu.getNomDesc());
pstmt.setString(2, qu.getQuestion());
pstmt.setString(3, qu.getType());
pstmt.setString(4, qu.getReponse());
pstmt.setDouble(5, qu.getNoteV());
pstmt.setDouble(6, qu.getNoteF());
pstmt.setString(7, qu.getNiveau());
pstmt.setString(8, qu.getMatiere());
pstmt.setString(9, qu.getChapitre());
pstmt.setString(10, qu.getExplication());
pstmt.setInt(11, p.getIdProf());
System.out.println("insert " + p.getIdProf());
if (pstmt == null) {
throw new SQLException();
} else {
return pstmt.executeUpdate() > 0;
}
}

Related

Spring Batch FlatFileItemWriter

salve sto cercando di leggere u oggetto e scivere un oggetto ma ricevo un errore :
Invalid property 'KDE22' of bean class [com.Bnl.Wl.Batch2.Model.EmployeeOut]: Bean property 'KDE22' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
#Bean
public FlatFileItemWriter<EmployeeOut> writer() throws IOException {
FlatFileItemWriter<EmployeeOut> writer = new FlatFileItemWriter<EmployeeOut>();
writer.setAppendAllowed(true);
System.out.println("conteggio " + conteggio);
writer.setResource(new FileSystemResource(dirOutputPath + dharControlEnvironment + nameAppOrigin
+ sdf1.format(timestamp) + String.format("%03d", conteggio + 1).toString() + ".txt"));
DelimitedLineAggregator<EmployeeOut> aggregator = new DelimitedLineAggregator<>();
BeanWrapperFieldExtractor<EmployeeOut> fieldExtractor = new BeanWrapperFieldExtractor<>();
fieldExtractor.setNames(EmployeeOut.fields());
aggregator.setFieldExtractor(fieldExtractor);
aggregator.setDelimiter("|");
System.out.println(writer.getExecutionContextKey(dharControlEnvironment).toString());
writer.setLineAggregator(aggregator);
writer.setHeaderCallback(
(org.springframework.batch.item.file.FlatFileHeaderCallback) new FlatFileHeaderCallback() {
public void writeHeader(Writer writer) throws IOException {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
writer.write("00" + "|" + sdf1.format(timestamp) + "|" + dharControlEnvironment + nameAppOrigin
+ "ANAGPILOTA");
}
});
writer.setFooterCallback(new FlatFileFooterCallback() {
#Override
public void writeFooter(Writer writer) throws IOException {
int cont = 0;
FileReader reader = new FileReader(dirOutputPath + dharControlEnvironment + nameAppOrigin
+ sdf1.format(timestamp) + String.format("%03d", conteggio + 1).toString() + extention);
BufferedReader in = new BufferedReader(reader);
while (in.readLine() != null)
cont++;
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
writer.write("99" + "|" + sdf1.format(timestamp) + "|" + dharControlEnvironment + nameAppOrigin + "|"
+ cont);
writer.write(System.lineSeparator());
}
});
return writer;
}
public class EmployeeItemProcessor implements ItemProcessor<Employee, EmployeeOut> {
private static final Logger log = LoggerFactory.getLogger(JobExecutionListener.class);
//private EmployeeOut itemOut = new EmployeeOut();
#Override
public EmployeeOut process(Employee item) throws Exception {
EmployeeOut itemOut = new EmployeeOut();
itemOut.setCOMPETENCE_DATE("afafafasdfadsfasdf");
itemOut.setDIVISA(item.getDIVISA());
itemOut.setCONTO_CONTABILE(item.getCONTO_CONTABILE());
itemOut.setTIPO_SCRITTURA(item.getID_SCRITTURA());
itemOut.setIMPORTO(item.getIMPORTO());
itemOut.setDATA_VALUTA(item.getDATA_VALUTA());
itemOut.setOM_BN(item.getOM_BN());
itemOut.setDOSSIER(item.getDOSSIER());
itemOut.setKDE1(item.getKDE1());
itemOut.setNDG(item.getNDG());
itemOut.setIBAN(item.getIBAN());
itemOut.setKDE2(item.getKDE2());
itemOut.setKDE3(item.getKDE3());
itemOut.setTIPO_EVENTO(item.getTIPO_EVENTO());
itemOut.setID_SCRITTURA(item.getID_SCRITTURA());
itemOut.setSIGLA_CIRCUITO(item.getSIGLA_CIRCUITO());
itemOut.setDATA_TESORERIA(item.getDATA_TESORERIA());
itemOut.setCOMPETENZA(item.getCOMPETENZA());
itemOut.setFLAG_SUBGROUP(item.getFLAG_SUBGROUP());
itemOut.setOPERATION(item.getOPERATION());
itemOut.setNew_field1("prova222");
itemOut.setNew_field1("prova");
itemOut.setNew_field2("sdfsdff");
log.info("filed 1 "+ itemOut.getNew_field1());
return itemOut;
}
}
package com.Bnl.Wl.Batch2.Model;
public class Employee {
protected String COMPETENCE_DATE;
protected String DIVISA;
protected String CONTO_CONTABILE;
protected String TIPO_SCRITTURA;
protected String IMPORTO;
protected String DATA_VALUTA;
protected String OM_BN;
protected String DOSSIER;
protected String KDE1;
protected String NDG;
protected String IBAN;
protected String KDE2;
protected String KDE3;
protected String TIPO_EVENTO;
protected String ID_SCRITTURA;
protected String SIGLA_CIRCUITO;
protected String DATA_TESORERIA;
protected String COMPETENZA;
protected String FLAG_SUBGROUP;
protected String OPERATION;
public Employee() {
}
public static String[] fields() {
return new String[] {"COMPETENCE_DATE",
"DIVISA",
"CONTO_CONTABILE",
"TIPO_SCRITTURA",
"IMPORTO",
"DATA_VALUTA",
"OM_BN",
"DOSSIER",
"KDE1",
"NDG",
"IBAN",
"KDE2",
"KDE3",
"TIPO_EVENTO",
"ID_SCRITTURA",
"SIGLA_CIRCUITO",
"DATA_TESORERIA",
"COMPETENZA",
"FLAG_SUBGROUP",
"OPERATION",
};
}
public String getCOMPETENCE_DATE() {
return COMPETENCE_DATE;
}
public void setCOMPETENCE_DATE(String cOMPETENCE_DATE) {
COMPETENCE_DATE = cOMPETENCE_DATE;
}
public String getDIVISA() {
return DIVISA;
}
public void setDIVISA(String dIVISA) {
DIVISA = dIVISA;
}
public String getCONTO_CONTABILE() {
return CONTO_CONTABILE;
}
public void setCONTO_CONTABILE(String cONTO_CONTABILE) {
CONTO_CONTABILE = cONTO_CONTABILE;
}
public String getTIPO_SCRITTURA() {
return TIPO_SCRITTURA;
}
public void setTIPO_SCRITTURA(String tIPO_SCRITTURA) {
TIPO_SCRITTURA = tIPO_SCRITTURA;
}
public String getIMPORTO() {
return IMPORTO;
}
public void setIMPORTO(String iMPORTO) {
IMPORTO = iMPORTO;
}
public String getDATA_VALUTA() {
return DATA_VALUTA;
}
public void setDATA_VALUTA(String dATA_VALUTA) {
DATA_VALUTA = dATA_VALUTA;
}
public String getOM_BN() {
return OM_BN;
}
public void setOM_BN(String oM_BN) {
OM_BN = oM_BN;
}
public String getDOSSIER() {
return DOSSIER;
}
public void setDOSSIER(String dOSSIER) {
DOSSIER = dOSSIER;
}
public String getKDE1() {
return KDE1;
}
public void setKDE1(String kDE1) {
KDE1 = kDE1;
}
public String getNDG() {
return NDG;
}
public void setNDG(String nDG) {
NDG = nDG;
}
public String getIBAN() {
return IBAN;
}
public void setIBAN(String iBAN) {
IBAN = iBAN;
}
public String getKDE2() {
return KDE2;
}
public void setKDE2(String kDE2) {
KDE2 = kDE2;
}
public String getKDE3() {
return KDE3;
}
public void setKDE3(String kDE3) {
KDE3 = kDE3;
}
public String getTIPO_EVENTO() {
return TIPO_EVENTO;
}
public void setTIPO_EVENTO(String tIPO_EVENTO) {
TIPO_EVENTO = tIPO_EVENTO;
}
public String getID_SCRITTURA() {
return ID_SCRITTURA;
}
public void setID_SCRITTURA(String iD_SCRITTURA) {
ID_SCRITTURA = iD_SCRITTURA;
}
public String getSIGLA_CIRCUITO() {
return SIGLA_CIRCUITO;
}
public void setSIGLA_CIRCUITO(String sIGLA_CIRCUITO) {
SIGLA_CIRCUITO = sIGLA_CIRCUITO;
}
public String getDATA_TESORERIA() {
return DATA_TESORERIA;
}
public void setDATA_TESORERIA(String dATA_TESORERIA) {
DATA_TESORERIA = dATA_TESORERIA;
}
public String getCOMPETENZA() {
return COMPETENZA;
}
public void setCOMPETENZA(String cOMPETENZA) {
COMPETENZA = cOMPETENZA;
}
public String getFLAG_SUBGROUP() {
return FLAG_SUBGROUP;
}
public void setFLAG_SUBGROUP(String fLAG_SUBGROUP) {
FLAG_SUBGROUP = fLAG_SUBGROUP;
}
public String getOPERATION() {
return OPERATION;
}
public void setOPERATION(String oPERATION) {
OPERATION = oPERATION;
}
}
package com.Bnl.Wl.Batch2.Model;
public class EmployeeOut extends Employee {
private String New_field1;
public String getNew_field1() {
return New_field1;
}
public void setNew_field1(String new_field1) {
New_field1 = new_field1;
}
public String getNew_field2() {
return New_field2;
}
public void setNew_field2(String new_field2) {
New_field2 = new_field2;
}
private String New_field2;
public EmployeeOut() {
super();
// TODO Auto-generated constructor stub
}
public static String[] fields() {
return new String[] { "COMPETENCE_DATE", "DIVISA", "CONTO_CONTABILE", "TIPO_SCRITTURA", "IMPORTO",
"DATA_VALUTA", "OM_BN", "DOSSIER", "KDE1", "NDG", "IBAN", "KDE22", "KDE3", "TIPO_EVENTO", "ID_SCRITTURA",
"SIGLA_CIRCUITO", "DATA_TESORERIA", "COMPETENZA", "FLAG_SUBGROUP", "OPERATION", "Field1", "Field2" };
}
}
object with n fields Object with n fields + m, but something goes wrong

Mockito tests pass except one verify

I have all my tests pass except this line in the first test
verify(reimbursementDAO).getById(REIMBURSEMENT_TO_PROCESS.getId());
see code below.
package com.revature.services;
public class ReimbursementServiceTest {
private static ReimbursementService reimbursementService;
private static ReimbursementDAO reimbursementDAO;
private Reimbursement REIMBURSEMENT_TO_PROCESS;
private Reimbursement GENERIC_REIMBURSEMENT_1;
private Optional<Reimbursement>
GENERIC_REIMBURSEMENT_2;
private List<Reimbursement> GENERIC_ALL_PENDING_REIMBURSEMENTS;
private User GENERIC_EMPLOYEE_1;
private User GENERIC_FINANCE_MANAGER_1;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
reimbursementDAO=mock(ReimbursementDAO.class);//(IReimbursementDAO.class);
reimbursementService = new ReimbursementService(reimbursementDAO);
//reimbursementDAO=new ReimbursementDAO();
}
#Before
public void setUp() throws Exception {
GENERIC_EMPLOYEE_1 = new User(1, "genericEmployee1", "genericPassword", Role.EMPLOYEE);
GENERIC_FINANCE_MANAGER_1 = new User(1, "genericManager1", "genericPassword", Role.FINANCE_MANAGER);
REIMBURSEMENT_TO_PROCESS = new Reimbursement(2, Status.PENDING, GENERIC_EMPLOYEE_1, null, 150.00);
GENERIC_REIMBURSEMENT_1 = new Reimbursement(1, Status.PENDING, GENERIC_EMPLOYEE_1, null, 100.00);
GENERIC_REIMBURSEMENT_2 = Optional.ofNullable(new Reimbursement(2, Status.APPROVED, GENERIC_EMPLOYEE_1,
GENERIC_FINANCE_MANAGER_1, 150.00));
GENERIC_ALL_PENDING_REIMBURSEMENTS = new ArrayList<Reimbursement>();
GENERIC_ALL_PENDING_REIMBURSEMENTS.add(GENERIC_REIMBURSEMENT_1);
}
#Test
public void testProcessPassesWhenUserIsFinanceManagerAndReimbursementExistsAndUpdateSuccessful()
throws Exception{
when(reimbursementDAO.getById(anyInt())).thenReturn(Optional.of(GENERIC_REIMBURSEMENT_1));
when(reimbursementDAO.update(any())).thenReturn(GENERIC_REIMBURSEMENT_2);
assertEquals(GENERIC_REIMBURSEMENT_2,
reimbursementService.process(REIMBURSEMENT_TO_PROCESS, Status.APPROVED,
GENERIC_FINANCE_MANAGER_1));
//verify(reimbursementDAO).getById(REIMBURSEMENT_TO_PROCESS.getId());
verify(reimbursementDAO).update(REIMBURSEMENT_TO_PROCESS);
}
#Test
public void testGetReimbursementByStatusPassesWhenReimbursementsAreSuccessfullyReturned() {
when(reimbursementDAO.getBystatus(any())).thenReturn(GENERIC_ALL_PENDING_REIMBURSEMENTS);
assertEquals(GENERIC_ALL_PENDING_REIMBURSEMENTS,
reimbursementService.getReimbursementsByStatus(Status.PENDING));
verify(reimbursementDAO).getBystatus(Status.PENDING);
}
}
public class ReimbursementDAO extends AbstractReimbursement
{
public Optional< Reimbursement> getById(int id) {
try(Connection conn = ConnectionFactory.getConnection())
{
String sql="select * from ers_reimbursements where reimb_id=?;";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1,id);
ResultSet rs= ps.executeQuery();
Reimbursement reimb=null;
UserService usrv=new UserService();
//reimb_id ,amount, submitted,resolved,description,author,receipt ,resolver,status,reimb_type
while(rs.next())
{
int reid=rs.getInt("reimb_id");
double ramount=rs.getInt("reimb_amount");
int res=rs.getInt( "resolver");
User resolver=null;
String description=rs.getString("description");
User rauthor= usrv.getUserById( rs.getInt("author")).get();
if(res>0)
{ resolver= usrv.getUserById(res).get(); }
int rstatus= rs.getInt("reimb_status");
Status r_status=Status.values()[--rstatus];
int reimb_type= rs.getInt("reimb_type");
ReimbType retype=ReimbType.values()[--reimb_type];
User oth=rauthor;
User re=resolver;
reimb=new Reimbursement(reid, r_status,oth,re,ramount);
return Optional.ofNullable(reimb);
}
}catch(SQLException e) { e.printStackTrace();};
return Optional.empty();
}
public List<Reimbursement> getBystatus(Status status) {
try(Connection conn = ConnectionFactory.getConnection())
{
String sql="select * from ers_reimbursements where reimb_status=?;";
PreparedStatement ps=conn.prepareStatement(sql);//,Statement.RETURN_GENERATED_KEYS);
int sta_id= status.ordinal()+1;
ps.setInt(1,sta_id);
ResultSet rs= ps.executeQuery();
Reimbursement reimb=null;
List<Reimbursement> reimbList=new ArrayList<Reimbursement>();
IUserService usrv=new UserService();
//reimb_id ,amount, submitted,resolved,description,author,receipt ,resolver,status,reimb_type
while(rs.next())
{
//int id, Status status, User author, User resolver, double amount
int reid=rs.getInt("reimb_id");
double ramount=rs.getInt("reimb_amount");
Optional<User> rauthor= usrv.getUserById( rs.getInt("author"));
User oth=null;
if(rauthor.isPresent())
{ oth=rauthor.get(); }
int resol=rs.getInt( "resolver");
Optional<User> resolver= usrv.getUserById(resol);
User re=null;
if(resolver.isPresent())
{ re=resolver.get(); }
else {re=null;}
int rstatus= rs.getInt("reimb_status");
Status r_status=Status.values()[--rstatus];//.PENDING;
int reimb_type= rs.getInt("reimb_type");
ReimbType retype=ReimbType.values()[--reimb_type];//.TRAVEL;
reimb=new Reimbursement(reid, r_status,oth,re,ramount);
reimbList.add(reimb);
}
return reimbList;
}catch(SQLException e) { e.printStackTrace();};
return null;
}
public Optional<Reimbursement> update(Reimbursement unprocessedReimbursement) {
try(Connection conn=ConnectionFactory.getConnection()) {
String sql="update ers_reimbursements set reimb_status=?,"
+ " resolver=?, resolved=? where reimb_id=?;";
PreparedStatement ps=conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
int id=unprocessedReimbursement.getId();
Status st=unprocessedReimbursement.getStatus();
ps.setObject(1,st);
ps.setInt(2,unprocessedReimbursement.getResolver().getId());
ps.setObject(3, LocalDateTime.now());
ps.setInt(4,id);
ps.executeUpdate();
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
if (generatedKeys.next()) {
int reimid=generatedKeys.getInt(1);
Optional<Reimbursement> reim=getById(reimid);
System.out.println("Reimb " + reim.get()+ " upLocalTimed!");
return reim;
}
}catch(SQLException e) {};
}catch(SQLException e) { e.printStackTrace();}
return Optional.empty();
}
}
public class ReimbursementService{
{
private final ReimbursementDAO reimbDao;
public ReimbursementService() {
this(new ReimbursementDAO());
}
public ReimbursementService(ReimbursementDAO userDAO2) {
this.reimbDao = userDAO2;
}
public Optional< Reimbursement> process(Reimbursement unprocessedReimbursement,
Status finalStatus, User resolver) throws Exception{
if (!resolver.getRole().equals(Role.FINANCE_MANAGER)) {
throw new RegistrationUnsuccessfulException("Resolver must be Finance Manager ");
}
// List<Reimbursement> l=DAO.getByStatus(Status.PENDING);
if(unprocessedReimbursement.getId()==0)
{ throw new Exception(" reimbursement not found"); }
if(unprocessedReimbursement.getStatus().equals(Status.PENDING))
{
unprocessedReimbursement.setResolver(resolver);
unprocessedReimbursement.setStatus(finalStatus);
Optional<Reimbursement> reimb=this.reimbDao.update(unprocessedReimbursement );
if(reimb.isPresent())
{ return reimb; }
else { throw new Exception("unsuccessful update");}
}
return Optional.ofNullable(null);
}
}
The verification
verify(reimbursementDAO).getById(REIMBURSEMENT_TO_PROCESS.getId());
fails because your service does not call the getById() method of your DAO.
It happens that your real DAO's update() method calls its own getById() method, but in your test you are using a mock DAO, where all functionality has been stubbed out. The update() method of the mock DAO does nothing more than return GENERIC_REIMBURSEMENT_2 because that's what your test sets it up to do.

Checkmarx: Unsafe object binding

We are using Java Spring framework. We have an endpoint for passing email object.
#RequestMapping(method = RequestMethod.POST, path = "/api/messaging/v1/emailMessages/actions/send")
String sendEmail(#RequestBody Email email);
Here checkmarx says: The email may unintentionally allow setting the value of cc in LinkedList<>, in the object Email.
Email Object is as follow:
public class Email {
private List<String> bcc = new LinkedList<>();
private List<String> cc = new LinkedList<>();
private String content;
private ContentType contentType = ContentType.TXT;
private String from;
private String returnPath;
private Date sent;
private String subject;
private List<EmailAttachment> attachments = new LinkedList<>();
private List<String> to = new LinkedList<>();
public List<String> getBcc() {
return bcc;
}
public void setBcc(String bcc) {
this.bcc = Collections.singletonList(bcc);
}
public void setBcc(List<String> bcc) {
this.bcc = bcc;
}
public List<String> getCc() {
return cc;
}
public void setCc(String cc) {
this.cc = Collections.singletonList(cc);
}
public void setCc(List<String> cc) {
this.cc = cc;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public ContentType getContentType() {
return contentType;
}
public void setContentType(ContentType contentType) {
this.contentType = contentType;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getReturnPath() {
return returnPath;
}
public void setReturnPath(String returnPath) {
this.returnPath = returnPath;
}
public Date getSent() {
return sent;
}
public void setSent(Date sent) {
this.sent = sent;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public List<String> getTo() {
return to;
}
public void setTo(String to) {
this.to = Collections.singletonList(to);
}
public void setTo(List<String> to) {
this.to = to;
}
public List<EmailAttachment> getAttachments() {
return attachments;
}
public void setAttachments(List<EmailAttachment> attachments) {
this.attachments = attachments;
}
public boolean equals(Object object) {
boolean equals = false;
if (object instanceof Email) {
Email that = (Email) object;
equals = Objects.equal(this.from, that.from)
&& Objects.equal(this.to, that.to)
&& Objects.equal(this.subject, that.subject)
&& Objects.equal(this.content, that.content);
}
return equals;
}
}
I don't understand these findings, how to solve this.
I have added Lombok with #Getter & #Setter annotation to resolve this issue.

Regarding DataControl in adf

I am developing an ADF web application with Oracle EBS as the backend to call the procedure(Jdeveloper 12 c).
I have invoked a method calling EBS procedure (return type is list) and the result is stored in arraylist. the list is used to create Data control.
What my problem is i have set values to the data control but when i added that dc to view it shows nothing. But on debugging it shows all the values are set in the array list.
Bean class calling EBS procedure in ApplicationModule
BindingContainer bindings = getBindings();
OperationBinding operationBinding = (OperationBinding) bindings.getOperationBinding("getIexpenseLogin");
List<EmployeePojo> result = (List<EmployeePojo>) operationBinding.execute();
System.out.println("Result= " + result);
employeeDC.getEmployeeLogin(result); // Here the list is passed to the Employee DC class to create data controll.
ApplicationModule Containing Custom Procedure
public List getIexpenseLogin(String username,String password){
CallableStatement cs=null;
List<EmployeePojo> empList=new ArrayList<>();
try{
cs=getDBTransaction().createCallableStatement("begin xx_oie_mob_login.oie_mob_login(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?); end;",0);
cs.setString(1,username);
cs.setString(2, password);
cs.registerOutParameter(3, Types.NUMERIC);
cs.registerOutParameter(4, Types.VARCHAR);
cs.registerOutParameter(5, Types.VARCHAR);
cs.registerOutParameter(6, Types.NUMERIC);
cs.registerOutParameter(7, Types.VARCHAR);
cs.registerOutParameter(8, Types.NUMERIC);
cs.registerOutParameter(9, Types.VARCHAR);
cs.registerOutParameter(10, Types.NUMERIC);
cs.registerOutParameter(11, Types.VARCHAR);
cs.registerOutParameter(12, Types.NUMERIC);
cs.registerOutParameter(13, Types.BLOB);
cs.registerOutParameter(14, Types.VARCHAR);
cs.registerOutParameter(15, Types.VARCHAR);
cs.executeUpdate();
if(cs!=null)
{
EmployeePojo ePojo=new EmployeePojo();
ePojo.setEmployeeId(cs.getString(3));
ePojo.setEmployeeName(cs.getString(4));
ePojo.setEmployeeNumber(cs.getString(5));
ePojo.setManagerId(cs.getString(6));
ePojo.setManagerName(cs.getString(7));
ePojo.setJobId(cs.getString(8));
ePojo.setJobName(cs.getString(9));
ePojo.setOrgId(cs.getString(10));
ePojo.setOrgName(cs.getString(11));
ePojo.setImgId(cs.getString(12));
ePojo.setImage(cs.getBlob(13));
empList.add(ePojo);
}
return empList;
}catch(SQLException e){
throw new JboException(e);
}
}
EmployeeDC class used to create Data controll
public class EmployeeDC {
public EmployeeDC() {
super();
}
BindingContainer bindings = null;
private List<EmployeePojo> employee_data_controll=null;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void setEmployee_data_controll(List<EmployeePojo> employee_data_controll) {
List<EmployeePojo> oldEmployee_data_controll = this.employee_data_controll;
this.employee_data_controll = employee_data_controll;
propertyChangeSupport.firePropertyChange("employee_data_controll", oldEmployee_data_controll,
employee_data_controll);
}
public List<EmployeePojo> getEmployee_data_controll() {
return employee_data_controll;
}
public void setPropertyChangeSupport(PropertyChangeSupport propertyChangeSupport) {
PropertyChangeSupport oldPropertyChangeSupport = this.propertyChangeSupport;
this.propertyChangeSupport = propertyChangeSupport;
propertyChangeSupport.firePropertyChange("propertyChangeSupport", oldPropertyChangeSupport,
propertyChangeSupport);
}
public PropertyChangeSupport getPropertyChangeSupport() {
return propertyChangeSupport;
}
public void getEmployeeLogin(List<EmployeePojo> result) {
setEmployee_data_controll(result);
getEmployee_data_controll();
System.out.println("DataControl=>"+getEmployee_data_controll().get(0));
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
}
EmployeePojo Class
public class EmployeePojo {
private String employeeId;
private String employeeName;
private String employeeNumber;
private String managerId;
private String managerName;
private String jobId;
private String jobName;
private String orgId;
private String orgName;
private String imgId;
private Blob image;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void setPropertyChangeSupport(PropertyChangeSupport propertyChangeSupport) {
this.propertyChangeSupport = propertyChangeSupport;
}
public PropertyChangeSupport getPropertyChangeSupport() {
return propertyChangeSupport;
}
public void setEmployeeId(String employeeId) {
String oldEmployeeId = this.employeeId;
this.employeeId = employeeId;
propertyChangeSupport.firePropertyChange("employeeId", oldEmployeeId, employeeId);
}
public String getEmployeeId() {
return employeeId;
}
public void setEmployeeName(String employeeName) {
String oldEmployeeName = this.employeeName;
this.employeeName = employeeName;
propertyChangeSupport.firePropertyChange("employeeName", oldEmployeeName, employeeName);
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeNumber(String employeeNumber) {
String oldEmployeeNumber = this.employeeNumber;
this.employeeNumber = employeeNumber;
propertyChangeSupport.firePropertyChange("employeeNumber", oldEmployeeNumber, employeeNumber);
}
public String getEmployeeNumber() {
return employeeNumber;
}
public void setManagerId(String managerId) {
String oldManagerId = this.managerId;
this.managerId = managerId;
propertyChangeSupport.firePropertyChange("managerId", oldManagerId, managerId);
}
public String getManagerId() {
return managerId;
}
public void setManagerName(String managerName) {
String oldManagerName = this.managerName;
this.managerName = managerName;
propertyChangeSupport.firePropertyChange("managerName", oldManagerName, managerName);
}
public String getManagerName() {
return managerName;
}
public void setJobId(String jobId) {
String oldJobId = this.jobId;
this.jobId = jobId;
propertyChangeSupport.firePropertyChange("jobId", oldJobId, jobId);
}
public String getJobId() {
return jobId;
}
public void setJobName(String jobName) {
String oldJobName = this.jobName;
this.jobName = jobName;
propertyChangeSupport.firePropertyChange("jobName", oldJobName, jobName);
}
public String getJobName() {
return jobName;
}
public void setOrgId(String orgId) {
String oldOrgId = this.orgId;
this.orgId = orgId;
propertyChangeSupport.firePropertyChange("orgId", oldOrgId, orgId);
}
public String getOrgId() {
return orgId;
}
public void setOrgName(String orgName) {
String oldOrgName = this.orgName;
this.orgName = orgName;
propertyChangeSupport.firePropertyChange("orgName", oldOrgName, orgName);
}
public String getOrgName() {
return orgName;
}
public void setImgId(String imgId) {
String oldImgId = this.imgId;
this.imgId = imgId;
propertyChangeSupport.firePropertyChange("imgId", oldImgId, imgId);
}
public String getImgId() {
return imgId;
}
public void setImage(Blob image) {
Blob oldImage = this.image;
this.image = image;
propertyChangeSupport.firePropertyChange("image", oldImage, image);
}
public Blob getImage() {
return image;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
}

jdbcTemplate.batchUpdate issue

How to convert this to return a jdbcTemplate.batchUpdate?
It needs to be executed to several tables.
#Override
public int delete(int id) {
String sql = "update user set deleted=1 where user_id = ?";
Object[] params = new Object[] { id };
try {
return jdbcTemplate.update(sql, params);
} catch (IncorrectResultSizeDataAccessException e) {
throw new UserNotFoundException("User.not.found");
}
}
#Override
public void delete(List<Integer> ids) {
String sql = "update user set deleted=1 where user_id = ?";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
#Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Integer userId = ids.get(i);
ps.setLong(1, userId );
}
#Override
public int getBatchSize() {
return ids.size();
}
});
}

Resources