Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions server/resources/META-INF/context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
<Context reloadable="true" swallowOutput="true" copyXML="true" override="true"> <!-- path="/" docBase="Device_Health" -->

<!-- -->
<Resource name="jdbc/postgresClientDBDeviceHealth" auth="Container" type="javax.sql.DataSource"
<Resource name="jdbc/postgresClientDBMMUG" auth="Container" type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/device_health_development"
username="${db.dh.username}" password="${db.dh.password}"
url="jdbc:postgresql://localhost:5433/livinggoods-ug"
username="${db.mm.username}" password="${db.mm.password}"
validationQuery="SELECT 1;" testOnBorrow="true"/>
<!-- factory="org.apache.commons.dbcp2.BasicDataSource" -->

<Resource name="jdbc/postgresClientDBMMUG" auth="Container" type="javax.sql.DataSource"
<Resource name="jdbc/postgresClientDBDeviceHealth" auth="Container" type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5433/livinggoods-ug"
username="${db.mm.username}" password="${db.mm.password}"
url="jdbc:postgresql://localhost:5432/device_health_local"
username="${db.dh.username}" password="${db.dh.password}"
validationQuery="SELECT 1;" testOnBorrow="true"/> <!-- ssh -L 5433:127.0.0.1:5433 user@server -->

<Resource name="jdbc/postgresClientDBMMKE" auth="Container" type="javax.sql.DataSource"
<Resource name="jdbc/postgresClientDBMMKE" auth="Container" type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5433/livinggoods-ke"
username="${db.mm.username}" password="${db.mm.password}"
validationQuery="SELECT 1;" testOnBorrow="true"/>
validationQuery="SELECT 1;" testOnBorrow="true"/>



Expand All @@ -43,14 +43,8 @@
value="300" />
<Parameter name="org.goods.living.tech.health.device.updateUSSDBalanceCodes"
value="false" />
<Parameter name="org.goods.living.tech.health.device.USSDBalanceCodes-63902"
value="*544*44#" /><!-- "*150*1*4*1#,*100*6*6*2#,*100*6*4*2#" -->
<Parameter name="org.goods.living.tech.health.device.USSDBalanceCodes-63903"
value="*175*4#" />
<Parameter name="org.goods.living.tech.health.device.USSDBalanceCodes-64110"
value="*150*1*4*1#" />
<Parameter name="org.goods.living.tech.health.device.USSDBalanceCodes-64101"
value="*175*4#" />
<Parameter name="org.goods.living.tech.health.device.USSDBalanceCodes-63902"
value="*544*44#"/>
<Parameter name="org.goods.living.tech.health.device.disableDatabalanceCheck"
value="false" />
<Parameter name="org.goods.living.tech.health.device.dataBalanceCheckTime"
Expand Down
7 changes: 5 additions & 2 deletions server/resources/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ appender.smtp.filter.threshold.level = ERROR
# RollingFileAppender will print logs in file which can be rotated based on time or size
appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName=${basePath}/deviceHealth.log
appender.rolling.filePattern=${basePath}/deviceHealth_%d{yyyyMMdd}.log.gz
#appender.rolling.fileName=${basePath}/deviceHealth.log
appender.rolling.fileName=/Users/dev-user/Desktop/PROJECTS/device_health_logs/deviceHealth.log
appender.rolling.fileNameErrors=/Users/dev-user/Desktop/PROJECTS/device_health_logs/deviceHealth.log
#
appender.rolling.filePattern=/Users/dev-user/Desktop/PROJECTS/device_health_logs/deviceHealth_%d{yyyyMMdd}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%p] %d %c %M - %msg%n
appender.rolling.policies.type = Policies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.goods.living.tech.health.device.jpa.controllers;

/**
*
* @author Chebet
*/

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.goods.living.tech.health.device.jpa.dao.Chw;
import org.goods.living.tech.health.device.jpa.dao.Stats;
import org.goods.living.tech.health.device.jpa.dao.Users;

public class ChwJpaController implements Serializable{

public ChwJpaController(EntityManagerFactory emf) {
this.emf = emf;
}

private EntityManagerFactory emf = null;

public EntityManager getEntityManager() {
return emf.createEntityManager();
}

public Chw findByUserName(String username) {

EntityManager em = getEntityManager();
try {
// CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
// Root<Users> rt = cq.from(Users.class);
// cq.select(em.getCriteriaBuilder().count(rt));
// Query q = em.createQuery(cq);

List<Chw> list = em.createNamedQuery("Chw.findByUsername").setParameter("username", username)
.getResultList();

System.out.print("The user is found and " + list.toString());
return list.size() > 0 ? list.get(0) : null;
} finally {
em.close();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public MedicJpaController getMedicJpaController() {
public AdminUsersJpaController getAdminUsersJpaController() {
return new AdminUsersJpaController(entityManagerFactoryDH);
}

@Produces
public ChwJpaController getChwJpaController() {
return new ChwJpaController(entityManagerFactoryDH);
}

void setUp() throws Exception {
entityManagerFactoryDH = Persistence.createEntityManagerFactory("postgresClientDBDeviceHealth");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,9 @@ public MedicUser findByUsername(String db, String username) {
mu.setSupervisor((Boolean) o[5]);
// l.add(mu);
// }
logger.error(mu.toString());
return mu;
} catch (NoResultException e) {
logger.error(e);
return new MedicUser();
} catch (Exception e) {
logger.error(e);
return null;
} finally {
} finally {
em.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;

import org.goods.living.tech.health.device.jpa.controllers.exceptions.IllegalOrphanException;
import org.goods.living.tech.health.device.jpa.controllers.exceptions.NonexistentEntityException;
Expand Down Expand Up @@ -60,7 +62,8 @@ public void create(Users users) {
}
}
em.getTransaction().commit();
} finally {
}
finally {
if (em != null) {
em.close();
}
Expand Down Expand Up @@ -207,21 +210,30 @@ public int getUsersCount() {
}

public Users findByUserNameAndAndroidId(String username, String androidId) {


System.out.print("findByUserNameAndAndroidId Called ");

EntityManager em = getEntityManager();
try {
// CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
// Root<Users> rt = cq.from(Users.class);
// cq.select(em.getCriteriaBuilder().count(rt));
// Query q = em.createQuery(cq);


List<Users> list = em.createNamedQuery("Users.findByUserNameAndAndroidId")
.setParameter("username", username).setParameter("androidId", androidId).getResultList();


System.out.print("findByUserNameAndAndroidId Called - Username" + username + list.size());

return list.size() > 0 ? list.get(0) : null;
} finally {


}catch(Exception ex) {
System.out.print("findByUserNameAndAndroidId Called ERROR");
}


finally {
em.close();
}
return null;

}

Expand Down Expand Up @@ -262,16 +274,17 @@ public List<Users> findByUserNameLike(String username) {
}

}

//@Transactional(noRollbackFor = Exception.class)
public Users update(Users users) {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();

users = em.merge(users);
em.getTransaction().commit();
return users;
} finally {
}
finally {
em.close();
}
}
Expand Down
160 changes: 160 additions & 0 deletions server/src/org/goods/living/tech/health/device/jpa/dao/Chw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.goods.living.tech.health.device.jpa.dao;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.TypeDef;

import com.vladmihalcea.hibernate.type.json.JsonNodeBinaryType;
/**
*
* @author ernestmurimi
*/
@Entity
@Table(name = "chw")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Chw.findAll", query = "SELECT c FROM Chw c")
, @NamedQuery(name = "Chw.findByUsername", query = "SELECT c FROM Chw c WHERE c.username = :username")
, @NamedQuery(name = "Chw.findByContactId", query = "SELECT c FROM Chw c WHERE c.contactId = :contactId")
, @NamedQuery(name = "Chw.findByChwName", query = "SELECT c FROM Chw c WHERE c.chwName = :chwName")
, @NamedQuery(name = "Chw.findByBranchName", query = "SELECT c FROM Chw c WHERE c.branchName = :branchName")
, @NamedQuery(name = "Chw.findByChwPhone", query = "SELECT c FROM Chw c WHERE c.chwPhone = :chwPhone")
, @NamedQuery(name = "Chw.findByCountry", query = "SELECT c FROM Chw c WHERE c.country = :country")
, @NamedQuery(name = "Chw.findBySupervisorName", query = "SELECT c FROM Chw c WHERE c.supervisorName = :supervisorName")
, @NamedQuery(name = "Chw.findById", query = "SELECT c FROM Chw c WHERE c.id = :id")})
@TypeDef(name = "jsonb-node", typeClass = JsonNodeBinaryType.class)
public class Chw implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "username")
private String username;
@Basic(optional = false)
@Column(name = "contact_id")
private String contactId;
@Column(name = "chw_name")
private String chwName;
@Column(name = "branch_name")
private String branchName;
@Column(name = "chw_phone")
private String chwPhone;
@Column(name = "country")
private String country;
@Column(name = "supervisor_name")
private String supervisorName;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Long id;

public Chw() {

}

public Chw(Long id) {
this.id = id;
}

public Chw(Long id, String contactId) {
this.id = id;
this.contactId = contactId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getContactId() {
return contactId;
}

public void setContactId(String contactId) {
this.contactId = contactId;
}

public String getChwName() {
return chwName;
}

public void setChwName(String chwName) {
this.chwName = chwName;
}

public String getBranchName() {
return branchName;
}

public void setBranchName(String branchName) {
this.branchName = branchName;
}

public String getChwPhone() {
return chwPhone;
}

public void setChwPhone(String chwPhone) {
this.chwPhone = chwPhone;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public String getSupervisorName() {
return supervisorName;
}

public void setSupervisorName(String supervisorName) {
this.supervisorName = supervisorName;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Chw)) {
return false;
}
Chw other = (Chw) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}

@Override
public String toString() {
return "org.goods.living.tech.health.device.jpa.dao.Chw[ id=" + id + " ]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @author bensonbundi
*/
@Entity
@Table(name = "data_balance", schema = "events")
@Table(name = "data_balance")
@XmlRootElement
@NamedQueries({ @NamedQuery(name = "DataBalance.findAll", query = "SELECT d FROM DataBalance d"),
@NamedQuery(name = "DataBalance.findById", query = "SELECT d FROM DataBalance d WHERE d.id = :id"),
Expand Down
Loading