diff --git a/src/main/java/com/yojana/model/project/Report.java b/src/main/java/com/yojana/model/project/Report.java index d2f6677abac3aac85b96abdda6d4132c7674e3c3..e1e18bea82597de2c8f637d7d27499f7e792faa9 100644 --- a/src/main/java/com/yojana/model/project/Report.java +++ b/src/main/java/com/yojana/model/project/Report.java @@ -2,8 +2,9 @@ package com.yojana.model.project; import java.io.Serializable; import java.util.Date; +import java.util.List; + import javax.persistence.Embedded; -import org.primefaces.shaded.json.JSONObject; import com.fasterxml.jackson.annotation.JsonProperty; import com.yojana.model.auditable.Audit; import com.yojana.model.auditable.Auditable; @@ -19,51 +20,21 @@ public class Report implements Auditable, Serializable { @Embedded private Audit audit; + @JsonProperty("Type") + private String type; - @JsonProperty("id") - private String id; - - @JsonProperty("projectID") - private String projectId; - - @JsonProperty("projectName") - private String projectName; - - @JsonProperty("projectBudget") - private float projectBudget; - - @JsonProperty("projectInitialEstimate") - private float projectInitialEstimate; - - @JsonProperty("projectDescription") - private String projectDes; - - @JsonProperty("projectStatus") - private ProjectStatus status; + @JsonProperty("Frame") + private String frame; - @JsonProperty("projectManagerID") - private int projectManagerId; - - @JsonProperty("projectManagerName") - private String projectManagerName; - - @JsonProperty("projectManagerUsername") - private String projectManagerUsername; - - @JsonProperty("projectManagerPassword") - private String projectManagerPassword; - - @JsonProperty("reportCreatedAt") + @JsonProperty("Date") private Date reportCreatedAt; - @JsonProperty("projectCreatedAt") - private Date projectCreatedAt; + @JsonProperty("ProjectID") + private String projectId; - @JsonProperty("projectUpdatedAt") - private Date projectUpdatedAt; + @JsonProperty("Data") + List<WorkPackage> data; - @JsonProperty("info") - private JSONObject info; public Report() {} @@ -77,22 +48,6 @@ public class Report implements Auditable, Serializable { this.audit = audit; } - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public JSONObject getInfo() { - return info; - } - - public void setInfo(JSONObject info) { - this.info = info; - } - public String getProjectId() { return projectId; } @@ -101,78 +56,6 @@ public class Report implements Auditable, Serializable { this.projectId = projectId; } - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public float getProjectBudget() { - return projectBudget; - } - - public void setProjectBudget(float projectBudget) { - this.projectBudget = projectBudget; - } - - public float getProjectInitialEstimate() { - return projectInitialEstimate; - } - - public void setProjectInitialEstimate(float projectInitialEstimate) { - this.projectInitialEstimate = projectInitialEstimate; - } - - public String getProjectDes() { - return projectDes; - } - - public void setProjectDes(String projectDes) { - this.projectDes = projectDes; - } - - public ProjectStatus getStatus() { - return status; - } - - public void setStatus(ProjectStatus status) { - this.status = status; - } - - public int getProjectManagerId() { - return projectManagerId; - } - - public void setProjectManagerId(int projectManagerId) { - this.projectManagerId = projectManagerId; - } - - public String getProjectManagerName() { - return projectManagerName; - } - - public void setProjectManagerName(String projectManagerName) { - this.projectManagerName = projectManagerName; - } - - public String getProjectManagerUsername() { - return projectManagerUsername; - } - - public void setProjectManagerUsername(String projectManagerUsername) { - this.projectManagerUsername = projectManagerUsername; - } - - public String getProjectManagerPassword() { - return projectManagerPassword; - } - - public void setProjectManagerPassword(String projectManagerPassword) { - this.projectManagerPassword = projectManagerPassword; - } - public Date getReportCreatedAt() { return reportCreatedAt; } @@ -181,20 +64,28 @@ public class Report implements Auditable, Serializable { this.reportCreatedAt = reportCreatedAt; } - public Date getProjectCreatedAt() { - return projectCreatedAt; + public List<WorkPackage> getData() { + return data; + } + + public void setData(List<WorkPackage> data) { + this.data = data; + } + + public String getType() { + return type; } - public void setProjectCreatedAt(Date projectCreatedAt) { - this.projectCreatedAt = projectCreatedAt; + public void setType(String type) { + this.type = type; } - public Date getProjectUpdatedAt() { - return projectUpdatedAt; + public String getFrame() { + return frame; } - public void setProjectUpdatedAt(Date projectUpdatedAt) { - this.projectUpdatedAt = projectUpdatedAt; + public void setFrame(String frame) { + this.frame = frame; } } diff --git a/src/main/java/com/yojana/model/project/WorkPackage.java b/src/main/java/com/yojana/model/project/WorkPackage.java index 6a1042b84be99c2def43a3c75e42d52ef3d5431a..0329db72d5078c7190bf76f01db9028e2de09e14 100644 --- a/src/main/java/com/yojana/model/project/WorkPackage.java +++ b/src/main/java/com/yojana/model/project/WorkPackage.java @@ -1,250 +1,255 @@ -package com.yojana.model.project; - -import java.io.Serializable; -import java.util.Date; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.yojana.model.auditable.Audit; -import com.yojana.model.auditable.AuditListener; -import com.yojana.model.auditable.Auditable; -import com.yojana.model.employee.Employee; - -@Entity -@Table(name = "WorkPackage") -@EntityListeners(AuditListener.class) -public class WorkPackage implements Auditable, Serializable { - - /** - * - */ - private static final long serialVersionUID = 7739894210058516672L; - - @Embedded - private Audit audit; - - @EmbeddedId - private WorkPackagePK workPackagePk; - - @JoinColumn(name = "ProjectID", insertable = false, updatable = false) - @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE }) - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - private Project project; - - @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) - @JoinColumns({ - @JoinColumn(name = "ParentWorkPackageID", referencedColumnName = "WorkPackageID", insertable = false, updatable = false), - @JoinColumn(name = "ProjectID", referencedColumnName = "ProjectID", insertable = false, updatable = false) - }) - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - private WorkPackage parentWP; - - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "parentWP") - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - private Set<WorkPackage> childWPs; - - @Column(name = "ParentWorkPackageID", insertable = false, updatable = false) - private String parentWPId; - - @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) - @JoinColumn(name = "ResponsibleEngineerID") - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - private Employee responsibleEngineer; - - @Column(name = "WorkPackageName") - private String workPackageName; - - @Column(name = "Descrip", columnDefinition="TEXT") - private String description; - - @Column(name = "IsLowestLevel") - private boolean isLowestLevel; - - @Column(name = "AllocatedBudget") - private float allocatedBudget; - - @Column(name = "InitialEstimate") - private float initialEstimate; - - @Column(name = "Charged") - private float charged; - - @Column(name = "CostAtCompletion") - private float costAtCompletion; - - @Temporal(TemporalType.DATE) - @Column(name = "DueAt") - private Date dueAt; - - @Enumerated(EnumType.STRING) - @Column(name = "Stat", columnDefinition = "enum") - private WorkPackageStatus status; - - @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @JoinTable( - name = "EmployeePackage", - joinColumns = { - @JoinColumn(name = "WorkPackageID", referencedColumnName = "WorkPackageID", insertable = false, updatable = false), - @JoinColumn(name = "ProjectID", referencedColumnName = "ProjectID", insertable = false, updatable = false) - }, - inverseJoinColumns = { @JoinColumn(name = "EmpID", referencedColumnName = "EmpID") } - ) - private Set<Employee> employees; - - public Audit getAudit() { - return audit; - } - - public void setAudit(Audit audit) { - this.audit = audit; - } - - public WorkPackagePK getWorkPackagePk() { - return workPackagePk; - } - - public void setWorkPackagePk(WorkPackagePK workPackagePk) { - this.workPackagePk = workPackagePk; - } - - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - - public WorkPackage getParentWP() { - return parentWP; - } - - public void setParentWP(WorkPackage parentWP) { - this.parentWP = parentWP; - } - - public Set<WorkPackage> getChildWPs() { - return childWPs; - } - - public void setChildWPs(Set<WorkPackage> childWPs) { - this.childWPs = childWPs; - } - - public String getParentWPId() { - return parentWPId; - } - - public void setParentWPId(String parentWPId) { - this.parentWPId = parentWPId; - } - - public Employee getResponsibleEngineer() { - return responsibleEngineer; - } - - public void setResponsibleEngineer(Employee responsibleEngineer) { - this.responsibleEngineer = responsibleEngineer; - } - - public String getWorkPackageName() { - return workPackageName; - } - - public void setWorkPackageName(String workPackageName) { - this.workPackageName = workPackageName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean isLowestLevel() { - return isLowestLevel; - } - - public void setLowestLevel(boolean isLowestLevel) { - this.isLowestLevel = isLowestLevel; - } - - public float getAllocatedBudget() { - return allocatedBudget; - } - - public void setAllocatedBudget(float allocatedBudget) { - this.allocatedBudget = allocatedBudget; - } - - public float getInitialEstimate() { - return initialEstimate; - } - - public void setInitialEstimate(float initialEstimate) { - this.initialEstimate = initialEstimate; - } - - public float getCharged() { - return charged; - } - - public void setCharged(float charged) { - this.charged = charged; - } - - public float getCostAtCompletion() { - return costAtCompletion; - } - - public void setCostAtCompletion(float costAtCompletion) { - this.costAtCompletion = costAtCompletion; - } - - public Date getDueAt() { - return dueAt; - } - - public void setDueAt(Date dueAt) { - this.dueAt = dueAt; - } - - public WorkPackageStatus getStatus() { - return status; - } - - public void setStatus(WorkPackageStatus status) { - this.status = status; - } - - public Set<Employee> getEmployees() { - return employees; - } - - public void setEmployees(Set<Employee> employees) { - this.employees = employees; - } - -} +package com.yojana.model.project; + +import java.io.Serializable; +import java.util.Date; +import java.util.Set; + +import javax.inject.Inject; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.yojana.model.auditable.Audit; +import com.yojana.model.auditable.AuditListener; +import com.yojana.model.auditable.Auditable; +import com.yojana.model.employee.Employee; + +@Entity +@Table(name = "WorkPackage") +@EntityListeners(AuditListener.class) +public class WorkPackage implements Auditable, Serializable { + + /** + * + */ + private static final long serialVersionUID = 7739894210058516672L; + + @Embedded + private Audit audit; + + @EmbeddedId + private WorkPackagePK workPackagePk; + + @JoinColumn(name = "ProjectID", insertable = false, updatable = false) + @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE }) + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private Project project; + + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumns({ + @JoinColumn(name = "ParentWorkPackageID", referencedColumnName = "WorkPackageID", insertable = false, updatable = false), + @JoinColumn(name = "ProjectID", referencedColumnName = "ProjectID", insertable = false, updatable = false) + }) + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private WorkPackage parentWP; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "parentWP") + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private Set<WorkPackage> childWPs; + + @Column(name = "ParentWorkPackageID", insertable = false, updatable = false) + private String parentWPId; + + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "ResponsibleEngineerID") + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private Employee responsibleEngineer; + + @Column(name = "WorkPackageName") + private String workPackageName; + + @Column(name = "Descrip", columnDefinition="TEXT") + private String description; + + @Column(name = "IsLowestLevel") + private boolean isLowestLevel; + + @Column(name = "AllocatedBudget") + private float allocatedBudget; + + @Column(name = "InitialEstimate") + private float initialEstimate; + + @Column(name = "Charged") + private float charged; + + @Column(name = "CostAtCompletion") + private float costAtCompletion; + + @Temporal(TemporalType.DATE) + @Column(name = "DueAt") + private Date dueAt; + + @Enumerated(EnumType.STRING) + @Column(name = "Stat", columnDefinition = "enum") + private WorkPackageStatus status; + + @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @JoinTable( + name = "EmployeePackage", + joinColumns = { + @JoinColumn(name = "WorkPackageID", referencedColumnName = "WorkPackageID", insertable = false, updatable = false), + @JoinColumn(name = "ProjectID", referencedColumnName = "ProjectID", insertable = false, updatable = false) + }, + inverseJoinColumns = { @JoinColumn(name = "EmpID", referencedColumnName = "EmpID") } + ) + private Set<Employee> employees; + + public WorkPackage() { + + } + + public Audit getAudit() { + return audit; + } + + public void setAudit(Audit audit) { + this.audit = audit; + } + + public WorkPackagePK getWorkPackagePk() { + return workPackagePk; + } + + public void setWorkPackagePk(WorkPackagePK workPackagePk) { + this.workPackagePk = workPackagePk; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public WorkPackage getParentWP() { + return parentWP; + } + + public void setParentWP(WorkPackage parentWP) { + this.parentWP = parentWP; + } + + public Set<WorkPackage> getChildWPs() { + return childWPs; + } + + public void setChildWPs(Set<WorkPackage> childWPs) { + this.childWPs = childWPs; + } + + public String getParentWPId() { + return parentWPId; + } + + public void setParentWPId(String parentWPId) { + this.parentWPId = parentWPId; + } + + public Employee getResponsibleEngineer() { + return responsibleEngineer; + } + + public void setResponsibleEngineer(Employee responsibleEngineer) { + this.responsibleEngineer = responsibleEngineer; + } + + public String getWorkPackageName() { + return workPackageName; + } + + public void setWorkPackageName(String workPackageName) { + this.workPackageName = workPackageName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isLowestLevel() { + return isLowestLevel; + } + + public void setLowestLevel(boolean isLowestLevel) { + this.isLowestLevel = isLowestLevel; + } + + public float getAllocatedBudget() { + return allocatedBudget; + } + + public void setAllocatedBudget(float allocatedBudget) { + this.allocatedBudget = allocatedBudget; + } + + public float getInitialEstimate() { + return initialEstimate; + } + + public void setInitialEstimate(float initialEstimate) { + this.initialEstimate = initialEstimate; + } + + public float getCharged() { + return charged; + } + + public void setCharged(float charged) { + this.charged = charged; + } + + public float getCostAtCompletion() { + return costAtCompletion; + } + + public void setCostAtCompletion(float costAtCompletion) { + this.costAtCompletion = costAtCompletion; + } + + public Date getDueAt() { + return dueAt; + } + + public void setDueAt(Date dueAt) { + this.dueAt = dueAt; + } + + public WorkPackageStatus getStatus() { + return status; + } + + public void setStatus(WorkPackageStatus status) { + this.status = status; + } + + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + +} diff --git a/src/main/java/com/yojana/services/project/ReportService.java b/src/main/java/com/yojana/services/project/ReportService.java index 559747bbce70084185a2bc78218d95f529b752fc..77d500ea8929ddeadb7502048eb106013332f713 100644 --- a/src/main/java/com/yojana/services/project/ReportService.java +++ b/src/main/java/com/yojana/services/project/ReportService.java @@ -1,48 +1,50 @@ package com.yojana.services.project; -import java.util.UUID; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.Produces; import javax.inject.Inject; +import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; import com.yojana.access.ProjectManager; -import com.yojana.model.employee.Credential; -import com.yojana.model.employee.Employee; +import com.yojana.access.WorkPackageManager; import com.yojana.model.project.Project; import com.yojana.model.project.Report; +import com.yojana.model.project.WorkPackage; import com.yojana.response.APIResponse; import com.yojana.response.errors.ErrorMessageBuilder; import com.yojana.security.annotations.Secured; +import java.util.List; -@Path("/reports") @Secured +@Path("/reports") public class ReportService { @Inject private ProjectManager projectManager; + + @Inject + private WorkPackageManager wpManager; - public Response createReport(String projectId) { + @GET + @Path("/earnedValue/{projectId}") + @Produces(MediaType.APPLICATION_JSON) + public Response getReport (@PathParam("projectId") String projectId) { Project project = projectManager.find(projectId); APIResponse res = new APIResponse(); if (project == null) { res.getErrors().add(ErrorMessageBuilder.notFoundSingle("report", projectId, null)); return Response.status(Response.Status.NOT_FOUND).entity(res).build(); } - Employee projectManager = project.getProjectManager(); - Credential credential = projectManager.getCredential(); Report report = new Report(); - report.setId(UUID.randomUUID().toString()); + report.setType("status"); + report.setFrame("weekly"); + report.setReportCreatedAt(project.getAudit().getCreatedAt()); report.setProjectId(project.getId()); - report.setProjectName(project.getName()); - report.setProjectBudget(project.getBudget()); - report.setProjectInitialEstimate(project.getInitialEstimate()); - report.setProjectDes(project.getDescription()); - report.setStatus(project.getStatus()); - report.setProjectManagerId(projectManager.getId()); - report.setProjectManagerName(projectManager.getFullName()); - report.setProjectManagerUsername(credential.getUsername()); - report.setProjectManagerPassword(credential.getPassword()); - report.setProjectCreatedAt(project.getAudit().getCreatedAt()); - report.setProjectUpdatedAt(project.getAudit().getUpdatedAt()); + List<WorkPackage> data = wpManager.getAll(projectId); + report.setData(data); res.getData().put("report", report); return Response.ok().entity(res).build();