Skip to content

Commit

Permalink
Application working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
dancanangwenyi committed May 17, 2019
1 parent f12ce57 commit ee22251
Show file tree
Hide file tree
Showing 27 changed files with 11,443 additions and 144 deletions.
1 change: 1 addition & 0 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ Any value defined here will override the pom.xml file value but is only applicab
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
</properties>
</project-shared-configuration>
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
<version>1.0</version>
</dependency>
<!--<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
</dependency>-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
Expand Down
46 changes: 0 additions & 46 deletions src/main/java/com/mycompany/cassiopeia/cancerController.java

This file was deleted.

44 changes: 0 additions & 44 deletions src/main/java/com/mycompany/cassiopeia/cancerRepository.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.cassiopeia;
package com.mycompany.cassiopeia.config;

import java.util.Set;
import javax.ws.rs.core.Application;
Expand All @@ -12,24 +12,24 @@
*
* @author dancan
*/
@javax.ws.rs.ApplicationPath("webresources")
@javax.ws.rs.ApplicationPath("api")
public class ApplicationConfig extends Application {

@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
addRestResourceClasses(resources);
return resources;
}

/**
* Do not modify addRestResourceClasses() method.
* It is automatically populated with
* all resources defined in the project.
* If required, comment out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(com.mycompany.cassiopeia.CancerResource.class);
resources.add(com.mycompany.cassiopeia.resource.CancerResource.class);
resources.add(com.mycompany.cassiopeia.resource.SymptomResource.class);
}

}
49 changes: 49 additions & 0 deletions src/main/java/com/mycompany/cassiopeia/ejb/SymptomRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.cassiopeia.ejb;

import com.mycompany.cassiopeia.entity.Symptom;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
*
* @author dancan
*/
@Stateless
public class SymptomRepository {

@PersistenceContext(unitName="com.mycompany_cassiopeia_war_1.0-SNAPSHOTPU")
protected EntityManager em;

public EntityManager getEntityManager() {
return em;
}

public Symptom createSymptom(Symptom symptom){
getEntityManager().persist(symptom);
return symptom;
}

public List<Symptom> findAllSymptoms(){
TypedQuery<Symptom> query = getEntityManager().createQuery(
"SELECT s FROM Symptom s", Symptom.class);
return query.getResultList();
}

public Symptom findSymptom(int id){
return getEntityManager().find(Symptom.class, id);
}

public List<Symptom> addAllSymptoms(List<Symptom> list){
for(Symptom symptom: list){createSymptom(symptom);}
return list;
}

}
66 changes: 66 additions & 0 deletions src/main/java/com/mycompany/cassiopeia/ejb/cancerRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.cassiopeia.ejb;

import com.mycompany.cassiopeia.entity.Cancer;
import java.util.HashMap;
import javax.persistence.*;
import java.util.List;
import javax.ejb.Stateless;

/**
*
* @author dancan
*/
@Stateless
public class cancerRepository {
@PersistenceContext(unitName="com.mycompany_cassiopeia_war_1.0-SNAPSHOTPU")
protected EntityManager em;

public EntityManager getEntityManager() {
return em;
}


public Cancer createCancerName(Cancer cancer) {
// Cancer cancer = new Cancer(id);
// cancer.setCancerName(cancerName);
// cancer.setLethalDegree(lethalDegree);
// cancer.setTreatmentType(treatmentType);
getEntityManager().persist(cancer);
return cancer;
}

public Cancer findCancerName(int id) {
return getEntityManager().find(Cancer.class, id);
}

public List<Cancer> findAllCancerNames() {
TypedQuery<Cancer> query = getEntityManager().createQuery(
"SELECT c FROM Cancer c", Cancer.class);
return query.getResultList();
}
public boolean addListCancers(List<Cancer> list){
boolean dan = false;
try{
for(Cancer c:list){
/*Cancer c = new Cancer();
c.setLethalDegree(c_hm.get("lethalDegree").toString());
c.setLethalDegree(c_hm.get("treatmentType").toString());
c.setLethalDegree(c_hm.get("cancerName").toString());*/
createCancerName(c);
}
dan = true;
}
catch(Exception e){

}
finally{
return dan;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.cassiopeia;
package com.mycompany.cassiopeia.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
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.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
*
* @author dancan
*/
@Entity
@Table(name = "cancer")
@Table(name = "cancer", catalog = "cancerdb", schema = "")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Cancer.findAll", query = "SELECT c FROM Cancer c")
Expand All @@ -38,23 +42,25 @@ public class Cancer implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
@Column(name = "id", nullable = false)
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "cancerName")
@Column(name = "cancerName", nullable = false, length = 255)
private String cancerName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "LethalDegree")
@Column(name = "LethalDegree", nullable = false, length = 50)
private String lethalDegree;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "TreatmentType")
@Column(name = "TreatmentType", nullable = false, length = 50)
private String treatmentType;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "id")
private List<Symptom> symptomList;

public Cancer() {
}
Expand Down Expand Up @@ -102,6 +108,15 @@ public void setTreatmentType(String treatmentType) {
this.treatmentType = treatmentType;
}

@XmlTransient
public List<Symptom> getSymptomList() {
return symptomList;
}

public void setSymptomList(List<Symptom> symptomList) {
this.symptomList = symptomList;
}

@Override
public int hashCode() {
int hash = 0;
Expand All @@ -124,7 +139,7 @@ public boolean equals(Object object) {

@Override
public String toString() {
return "com.mycompany.cassiopeia.Cancer[ id=" + id + " ]";
return "com.mycompany.cassiopeia.entity.Cancer[ id=" + id + " ]";
}

}
Loading

0 comments on commit ee22251

Please sign in to comment.