Skip to content

Commit

Permalink
added User stack
Browse files Browse the repository at this point in the history
  • Loading branch information
slifty committed May 9, 2016
1 parent db7959a commit 97cc34e
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 13 deletions.
66 changes: 66 additions & 0 deletions src/main/java/org/openhmis/dao/TmpUserDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.openhmis.dao;


import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.openhmis.domain.TmpUser;

public class TmpUserDAO extends BaseDAO {

public TmpUserDAO() {
}

public TmpUser getTmpUserById(Integer userId) {
String queryString = "select user " +
"from TmpUser as user " +
"where user.userId =:userId";

Session session = getSession();
Query queryObject = session.createQuery(queryString);
queryObject.setParameter("userId", userId);
queryObject.setMaxResults(1);

List<TmpUser> results = queryObject.list();
session.close();

if(results.size() > 0)
return (TmpUser)results.get(0);
else
return null;
}

public TmpUser getTmpUserByExternalId(String externalId) {
String queryString = "select user " +
"from TmpUser as user " +
"where user.externalId =:externalId";

Session session = getSession();
Query queryObject = session.createQuery(queryString);
queryObject.setParameter("externalId", externalId);
queryObject.setMaxResults(1);

List<TmpUser> results = queryObject.list();
session.close();

if(results.size() > 0)
return (TmpUser)results.get(0);
else
return null;
}


@SuppressWarnings("unchecked")
public List<TmpUser> getTmpUsers() {
String queryString = "select user " +
"from TmpUser as user";

Session session = getSession();
Query queryObject = session.createQuery(queryString);
List<TmpUser> results = queryObject.list();
session.close();
return results;
}
}
111 changes: 111 additions & 0 deletions src/main/java/org/openhmis/domain/TmpUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.openhmis.domain;



// Generated Aug 5, 2015 10:00:15 PM by Hibernate Tools 4.3.1

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "TMP_USER")
public class TmpUser implements java.io.Serializable {
private Integer userId;
private String externalId;
private Integer canRead;
private Integer canWrite;
private Integer canAdmin;
private Date dateCreated;
private Date dateUpdated;

public TmpUser() {
}

public TmpUser(Integer userId, String externalId,
Integer canRead, Integer canWrite,
Integer canAdmin,
Date dateCreated, Date dateUpdated) {
this.userId = userId;
this.externalId = externalId;
this.canRead = canRead;
this.canWrite = canWrite;
this.canAdmin = canAdmin;
this.dateCreated = dateCreated;
this.dateUpdated = dateUpdated;
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "userId", unique = true, nullable = false)
public Integer getUserId() {
return this.userId;
}

public void setUserId(Integer userId) {
this.userId = userId;
}

@Column(name = "externalId")
public String getExternalId() {
return this.externalId;
}

public void setExternalId(String externalId) {
this.externalId = externalId;
}

@Column(name = "canRead")
public Integer getCanRead() {
return this.canRead;
}

public void setCanRead(Integer canRead) {
this.canRead = canRead;
}

@Column(name = "canWrite")
public Integer getCanWrite() {
return this.canWrite;
}

public void setCanWrite(Integer canWrite) {
this.canWrite = canWrite;
}

@Column(name = "canAdmin")
public Integer getCanAdmin() {
return this.canAdmin;
}

public void setCanAdmin(Integer canAdmin) {
this.canAdmin = canAdmin;
}

@Temporal(TemporalType.DATE)
@Column(name = "dateCreated", length = 10)
public Date getDateCreated() {
return this.dateCreated;
}

public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}

@Temporal(TemporalType.DATE)
@Column(name = "dateUpdated", length = 10)
public Date getDateUpdated() {
return this.dateUpdated;
}

public void setDateUpdated(Date dateUpdated) {
this.dateUpdated = dateUpdated;
}

}
117 changes: 117 additions & 0 deletions src/main/java/org/openhmis/dto/UserDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.openhmis.dto;


import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;

import org.openhmis.code.ClientDestination;
import org.openhmis.code.ClientEarlyExitReason;
import org.openhmis.code.ClientEmploymentType;
import org.openhmis.code.ClientExitAction;
import org.openhmis.code.ClientExpelledReason;
import org.openhmis.code.ClientHealthStatus;
import org.openhmis.code.ClientHousingAssessmentAtExit;
import org.openhmis.code.ClientHousingAssessmentDisposition;
import org.openhmis.code.ClientNotEmployedReason;
import org.openhmis.code.ClientProjectCompletionStatus;
import org.openhmis.code.ClientSubsidyInformation;
import org.openhmis.code.YesNoReason;

import com.fasterxml.jackson.annotation.JsonProperty;

@XmlRootElement
public class UserDTO {

private String userId;
private String externalId;
private Integer canRead;
private Integer canWrite;
private Integer canAdmin;

// Export Standard Fields
private Date dateCreated;
private Date dateUpdated;

public UserDTO() {}

@JsonProperty
public String getId() {
return userId;
}

@JsonProperty
public void setId(String userId) {
this.userId = userId;
}

@JsonProperty
public String getUserId() {
return userId;
}

@JsonProperty
public void setUserId(String userId) {
this.userId = userId;
}

@JsonProperty
public String getExternalId() {
return externalId;
}

@JsonProperty
public void setExternalId(String externalId) {
this.externalId = externalId;
}

@JsonProperty
public Integer getCanRead() {
return canRead;
}

@JsonProperty
public void setCanRead(Integer canRead) {
this.canRead = canRead;
}

@JsonProperty
public Integer getCanWrite() {
return canWrite;
}

@JsonProperty
public void setCanWrite(Integer canWrite) {
this.canWrite = canWrite;
}

@JsonProperty
public Integer getCanAdmin() {
return canAdmin;
}

@JsonProperty
public void setCanAdmin(Integer canAdmin) {
this.canAdmin = canAdmin;
}

@JsonProperty
public Date getDateCreated() {
return dateCreated;
}

@JsonProperty
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}

@JsonProperty
public Date getDateUpdated() {
return dateUpdated;
}

@JsonProperty
public void setDateUpdated(Date dateUpdated) {
this.dateUpdated = dateUpdated;
}
}
Loading

1 comment on commit 97cc34e

@kfogel
Copy link
Member

@kfogel kfogel commented on 97cc34e May 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In src/main/java/org/openhmis/manager/UserManager.java, are some comments left over from an original file on which stuff here was based? I'm thinking of comments like:

// For each financialAssistance, collect and map the data
// Generate a PathClient from the input

...and maybe a few others.

Regarding that "Tmp" prefix: ah, ISTR that you explained this earlier, and it has something to do with where our data model diverges from either Pathways or HUD. Is that right? Lots of other fields in src/main/java/org/openhmis/util/HibernateSessionFactory.java have a "Tmp" prefix too. But I couldn't find anything in the top-level docs/ directory or elsewhere that explains it. We should probably have something.

Just noticing now that we don't have any i18n in place (e.g., throw new Error("You are not authorized to access this content"); -- it's just a direct string in English right now. Hmrmm. That is not really related to this commit, of course; I'm just noting it so that... okay: filed issue #54 about it.

I pondered the implication that we could, in theory, have a user who can write but not read. But whatevs: no reason not to permit that down at the system level. If we have higher-level validations that prevent that from ever happening, that's good & would be the right place for such checks anyway.

Please sign in to comment.