diff --git a/nb-configuration.xml b/nb-configuration.xml new file mode 100644 index 0000000..4da1f6c --- /dev/null +++ b/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + ide + + diff --git a/pom.xml b/pom.xml index ae635db..c22360e 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,18 @@ javaee-api ${version.dependency.javaee} provided + + + com.sun.mail + javax.mail + + + + + + hsqldb + hsqldb + 1.8.0.10 diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java new file mode 100644 index 0000000..d10cb3b --- /dev/null +++ b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java @@ -0,0 +1,202 @@ +package com.cortez.samples.javaee7angular.data; + +import java.io.Serializable; +import java.math.BigDecimal; +import javax.persistence.*; + +/** + * Simple entity. + * + * @author Roberto Cortez + */ +@Entity +@Table(name = "ISSUE") +@NamedQueries({ + @NamedQuery(name = "Issue.findAll", query = "SELECT m FROM Issue m")}) +public class Issue implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + //@GeneratedValue(strategy = GenerationType.SEQUENCE) + //@SequenceGenerator(name = "ID", sequenceName = "ID") + private Long id; + + @Column(name = "ISSUENUM") + private String issueNum; + + @Column(name = "P1RATE", precision = 7, scale = 5) + private BigDecimal p1Rate; + + @Column(name = "P2RATE", precision = 7, scale = 5) + private BigDecimal p2Rate; + + @Column(name = "BELONGS", columnDefinition="smallint(1) default '0'") + private short belongs; + + public short getBelongs() { + return belongs; + } + + public void setBelongs(short belongs) { + this.belongs = belongs; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getIssueNum() { + return issueNum; + } + + public void setIssueNum(String issueNum) { + this.issueNum = issueNum; + } + + public BigDecimal getP1Rate() { + return p1Rate; + } + + public BigDecimal getP2Rate() { + return p2Rate; + } + + public void setP1Rate(BigDecimal p1Rate) { + this.p1Rate = p1Rate; + } + + public void setP2Rate(BigDecimal p2Rate) { + this.p2Rate = p2Rate; + } + + public double getMrkDiff() { + if( p1Rate.doubleValue()>p2Rate.doubleValue() ) return p1Rate.doubleValue()-p2Rate.doubleValue(); + else return p2Rate.doubleValue()-p1Rate.doubleValue(); + } + + public void setWinningParty() { + if( p1Rate.doubleValue()>p2Rate.doubleValue() ) belongs=1; + else belongs=2; + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + public double getWiningPartyRate() { + if ( belongs == 1 ) return p1Rate.doubleValue(); + else return p2Rate.doubleValue(); + } + + public double getLoosingPartyRate() { + if ( belongs == 1 ) return p2Rate.doubleValue(); + else return p1Rate.doubleValue(); + } + + public String CalculateNewRates(double WinnersResolvedIssueRate, double LoosersResolvedIssueRate, int WinningParty ) { + //ofstream outResultFile( "result.txt", ios::app ); + String output=""; + output+="Old Rates for Issue "+issueNum+": "+p1Rate+", "+p2Rate+"\n"; +// outResultFile<<"Old Rates for Issue "<= 0 && Difference < 30 ) Factor = (1.0/0.3) * Difference; + else if ( Difference >=30 && Difference <= 100 ) Factor = 100; + } + else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) + { + if( Difference >= 0 && Difference < 10 ) Factor = 1.25 * Difference + 12.5; + else if( Difference >= 10 && Difference < 20 ) Factor = 25; + else if( Difference >= 20 && Difference < 40 ) Factor = ( 1.0 / 2.0 ) * Difference + 15; + else if( Difference >= 40 && Difference < 60 ) Factor = - ( 3.5 / 2.0 ) * Difference + 105; + else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 0.5 / 4.0 ) * Difference + 7.5; + } + else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) + { + if( Difference >= 0 && Difference < 10 ) Factor = 5; + else if( Difference >= 10 && Difference < 20 ) Factor = 0.75 * Difference - 2.5; + else if( Difference >= 20 && Difference < 40 ) Factor = 12.5; + else if( Difference >= 40 && Difference < 60 ) Factor = - ( 2.5 / 4.0 ) * Difference + 37.5; + else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 1.0 / 4.0 ) * Difference + 15; + } + else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { + if( Difference >= 0 && Difference < 10 ) Factor = ( 1.0 / 1.0 ) * Difference - 5; + else if( Difference >= 10 && Difference < 20 ) Factor = 5; + else if( Difference >= 20 && Difference < 40 ) Factor = - ( 0.5 / 1.0 ) * Difference + 20; + else if( Difference >= 40 && Difference <= 100 ) Factor = - 0.25 * Difference + 10; + } + else if( WinningIssueRate > 55 ) + { + if( Difference >= 0 && Difference <= 100 ) Factor = ( 1.0 / 1.0 ) * Difference - 100; + } + + return Factor/100.0; + } + + private double CalculateLoosingPartyRate(double WinningIssueRate, double Difference) { + double Factor=1; + if ( WinningIssueRate <= 10 ) + { + if( Difference >= 0 && Difference < 20 ) Factor = 25; + else if( Difference >= 20 && Difference < 30 ) Factor = ( 2.5 / 1.0 ) * Difference - 25; + else if( Difference >= 30 && Difference <= 100) Factor = 50; + } + else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) + { + if( Difference >= 0 && Difference < 30 ) Factor = 25; + else if( Difference >= 30 && Difference <= 100 ) Factor = -( 2.5 / 7.0 ) * Difference + 250 / 7; + } + else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) + { + if( Difference >= 0 && Difference < 40 ) Factor = 50; + else if( Difference >= 40 && Difference < 50 ) Factor = -( 2.5 / 1.0 ) * Difference + 150; + else if( Difference >= 50 && Difference <= 100 ) Factor = -( 0.5 / 1.0 ) * Difference + 50; + } + else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { + if( Difference >= 0 && Difference < 20 ) Factor = 75; + else if( Difference >= 20 && Difference < 30 ) Factor = -( 2.5 / 1.0 ) * Difference + 125; + else if( Difference >= 30 && Difference < 55 ) Factor = 50; + else if( Difference >= 55 && Difference < 60 ) Factor = -5 * Difference + 325; + else if( Difference >= 60 && Difference <= 100 ) Factor = -( 2.5 / 4.0 ) * Difference + 62.5; + } + else if( WinningIssueRate > 55 ) + { + if( Difference >= 0 && Difference < 30 ) Factor = 100; + else if( Difference >= 30 && Difference < 40 ) Factor = -( 2.5 / 1.0 ) * Difference + 175; + else if( Difference >= 40 && Difference < 50 ) Factor = 75; + else if( Difference >= 50 && Difference < 60 ) Factor = -( 2.5 / 1.0 ) * Difference + 200; + else if( Difference >= 60 && Difference <= 100 ) Factor = -( 5.0 / 4.0 ) * Difference + 125; + } + return Factor/100.0; + } + +} diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Person.java b/src/main/java/com/cortez/samples/javaee7angular/data/Person.java deleted file mode 100644 index a88f350..0000000 --- a/src/main/java/com/cortez/samples/javaee7angular/data/Person.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.cortez.samples.javaee7angular.data; - -import javax.persistence.*; - -/** - * Simple entity. - * - * @author Roberto Cortez - */ -@Entity -public class Person { - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id") - @SequenceGenerator(name = "id", sequenceName = "id") - private Long id; - - private String name; - - private String description; - - private String imageUrl; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getImageUrl() { - return imageUrl; - } - - public void setImageUrl(String link) { - this.imageUrl = link; - } - - @Override - public boolean equals(Object o) { - if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - - Person person = (Person) o; - - return id.equals(person.id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } -} diff --git a/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java b/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java new file mode 100644 index 0000000..7a5a4ff --- /dev/null +++ b/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java @@ -0,0 +1,126 @@ +/* + * 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.cortez.samples.javaee7angular.negotiation; + +import com.cortez.samples.javaee7angular.data.Issue; +import java.math.BigDecimal; +import java.util.List; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +/** + * + * @author Arkadios.Tsamourliadis + */ +@Stateless +@LocalBean +public class Negotiation { + + + @PersistenceContext(unitName = "myPU") + private EntityManager em; + + public String performNegotiation() { + List issuesList = getAllIssues(); + String output = CalculateNormRates(issuesList); + output += resolveIssues(issuesList); + + + System.out.println("output: \n"+output); + return output; + } + + public List getAllIssues() { + Query query = em.createNamedQuery("Issue.findAll"); + List results = query.getResultList(); + return results; + } + + private void normalizeRates(Issue issue, double p1sum, double p2sum){ + issue.setP1Rate(new BigDecimal(100.0*issue.getP1Rate().doubleValue()/p1sum)); + issue.setP2Rate(new BigDecimal(100.0*issue.getP2Rate().doubleValue()/p2sum)); + } + + private String CalculateNormRates(List issues) { + //ofstream outResultFile( "result.txt", ios::app ); + double p1sum=0; + double p2sum=0; + String calcTextBox=""; + + for (Issue issue : issues) { + p1sum += issue.getP1Rate().doubleValue(); + p2sum += issue.getP2Rate().doubleValue(); + /////////////////////////// + calcTextBox=calcTextBox+"Calculating SumS p1, p2: "+p1sum+", "+p2sum+"\r\n"; + calcTextBox=calcTextBox+" Issue name: "+issue.getIssueNum()+" rates: "+issue.getP1Rate()+" "+issue.getP2Rate()+"\r\n"; + } + //cout<<"\nSum of Party 1 Rates:"< issues) { + //ofstream outResultFile( "result.txt", ios::app ); + + String tmptextbox=""; + //At each iteration an Issue will be Resolved + for (int genIndex=0; genIndex < issues.size(); genIndex++) + { + double maxDiff=0; + int maxDiffIssueIndex=-1; + + //Find an Issue to Resolve + for (int i=0; i= maxDiff ) { + maxDiff = issues.get(i).getMrkDiff(); + maxDiffIssueIndex = i; + } + } + issues.get(maxDiffIssueIndex).setWinningParty(); //This Issue has just been resolved + + + tmptextbox = tmptextbox+"\r\nIssue "+issues.get(maxDiffIssueIndex).getIssueNum()+ + " won by party "+issues.get(maxDiffIssueIndex).getBelongs()+"\r\n"; + //outResultFile<<"\nIssue "< list; + private List list; public Integer getCurrentPage() { return currentPage; @@ -67,7 +67,7 @@ public List getList() { return list; } - public void setList(List list) { + public void setList(List list) { this.list = list; } } diff --git a/src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java similarity index 56% rename from src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java rename to src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java index 7af10e9..d5c723c 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java +++ b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java @@ -1,6 +1,7 @@ package com.cortez.samples.javaee7angular.rest; -import com.cortez.samples.javaee7angular.data.Person; +import com.cortez.samples.javaee7angular.data.Issue; +import com.cortez.samples.javaee7angular.negotiation.Negotiation; import com.cortez.samples.javaee7angular.pagination.PaginatedListWrapper; import javax.ejb.Stateless; @@ -11,6 +12,7 @@ import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import java.util.List; +import javax.ejb.EJB; /** * REST Service to expose the data to display in the UI grid. @@ -19,31 +21,36 @@ */ @Stateless @ApplicationPath("/resources") -@Path("persons") +@Path("issues") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) -public class PersonResource extends Application { +public class IssueResource extends Application { + + @PersistenceContext private EntityManager entityManager; + + @EJB + private Negotiation neg; - private Integer countPersons() { - Query query = entityManager.createQuery("SELECT COUNT(p.id) FROM Person p"); + private Integer countIssues() { + Query query = entityManager.createQuery("SELECT COUNT(p.id) FROM Issue p"); return ((Long) query.getSingleResult()).intValue(); } @SuppressWarnings("unchecked") - private List findPersons(int startPosition, int maxResults, String sortFields, String sortDirections) { + private List findIssue(int startPosition, int maxResults, String sortFields, String sortDirections) { Query query = - entityManager.createQuery("SELECT p FROM Person p ORDER BY p." + sortFields + " " + sortDirections); + entityManager.createQuery("SELECT p FROM Issue p ORDER BY p." + sortFields + " " + sortDirections); query.setFirstResult(startPosition); query.setMaxResults(maxResults); return query.getResultList(); } - private PaginatedListWrapper findPersons(PaginatedListWrapper wrapper) { - wrapper.setTotalResults(countPersons()); + private PaginatedListWrapper findIssues(PaginatedListWrapper wrapper) { + wrapper.setTotalResults(countIssues()); int start = (wrapper.getCurrentPage() - 1) * wrapper.getPageSize(); - wrapper.setList(findPersons(start, + wrapper.setList(findIssue(start, wrapper.getPageSize(), wrapper.getSortFields(), wrapper.getSortDirections())); @@ -52,7 +59,7 @@ private PaginatedListWrapper findPersons(PaginatedListWrapper wrapper) { @GET @Produces(MediaType.APPLICATION_JSON) - public PaginatedListWrapper listPersons(@DefaultValue("1") + public PaginatedListWrapper listIssues(@DefaultValue("1") @QueryParam("page") Integer page, @DefaultValue("id") @@ -66,37 +73,41 @@ public PaginatedListWrapper listPersons(@DefaultValue("1") paginatedListWrapper.setSortFields(sortFields); paginatedListWrapper.setSortDirections(sortDirections); paginatedListWrapper.setPageSize(10); - return findPersons(paginatedListWrapper); + return findIssues(paginatedListWrapper); } @GET @Path("{id}") - public Person getPerson(@PathParam("id") Long id) { - return entityManager.find(Person.class, id); + public Issue getIssue(@PathParam("id") Long id) { + if (id == -1){ + neg.performNegotiation(); + } + return entityManager.find(Issue.class, id); } + @POST - public Person savePerson(Person person) { - if (person.getId() == null) { - Person personToSave = new Person(); - personToSave.setName(person.getName()); - personToSave.setDescription(person.getDescription()); - personToSave.setImageUrl(person.getImageUrl()); - entityManager.persist(person); + public Issue saveIssue(Issue issue) { + if (issue.getId() == null) { + Issue issueToSave = new Issue(); + issueToSave.setIssueNum(issue.getIssueNum()); + issueToSave.setP1Rate(issue.getP1Rate()); + issueToSave.setP2Rate(issue.getP2Rate()); + entityManager.persist(issue); } else { - Person personToUpdate = getPerson(person.getId()); - personToUpdate.setName(person.getName()); - personToUpdate.setDescription(person.getDescription()); - personToUpdate.setImageUrl(person.getImageUrl()); - person = entityManager.merge(personToUpdate); + Issue issueToUpdate = getIssue(issue.getId()); + issueToUpdate.setIssueNum(issue.getIssueNum()); + issueToUpdate.setP1Rate(issue.getP1Rate()); + issueToUpdate.setP2Rate(issue.getP2Rate()); + issue = entityManager.merge(issueToUpdate); } - return person; + return issue; } @DELETE @Path("{id}") - public void deletePerson(@PathParam("id") Long id) { - entityManager.remove(getPerson(id)); + public void deleteIssue(@PathParam("id") Long id) { + entityManager.remove(getIssue(id)); } } diff --git a/src/main/resources/sql/create-mariadb-database.sql b/src/main/resources/sql/create-mariadb-database.sql new file mode 100644 index 0000000..35fd86d --- /dev/null +++ b/src/main/resources/sql/create-mariadb-database.sql @@ -0,0 +1,4 @@ +create user emcs identified by 'emcs'; +create database emcsdb CHARACTER SET = utf8 COLLATE utf8_bin; +grant all privileges on emcsdb.* to 'emcs'@'localhost'; +flush privileges; diff --git a/src/main/resources/sql/create.sql b/src/main/resources/sql/create.sql index 1af9fe2..3536b21 100644 --- a/src/main/resources/sql/create.sql +++ b/src/main/resources/sql/create.sql @@ -1,2 +1 @@ -CREATE SEQUENCE ID START WITH 100 -CREATE TABLE PERSON("ID" INTEGER not null primary key, "NAME" VARCHAR(50), "DESCRIPTION" VARCHAR(100), "IMAGEURL" VARCHAR(500)) +CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, ISSUENUM VARCHAR(50), P1RATE DECIMAL(7,5), P2RATE DECIMAL(7,5), BELONGS smallint(1), PRIMARY KEY (ID) ); diff --git a/src/main/resources/sql/drop.sql b/src/main/resources/sql/drop.sql index c93f0ed..4dfd8b4 100644 --- a/src/main/resources/sql/drop.sql +++ b/src/main/resources/sql/drop.sql @@ -1,2 +1 @@ -DROP TABLE PERSON -DROP SEQUENCE ID +DROP TABLE ISSUE diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index 6cda2cb..330144f 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,21 +1,27 @@ -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (1, 'Uzumaki Naruto', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140523045537/naruto/images/thumb/3/36/Naruto_Uzumaki.png/300px-Naruto_Uzumaki.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (2, 'Hatake Kakashi', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140616090940/naruto/images/thumb/b/b3/KakashiHatake.png/300px-KakashiHatake.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (3, 'Haruno Sakura', 'Konoha', 'http://vignette2.wikia.nocookie.net/naruto/images/b/ba/Sakurap2.png/revision/latest/scale-to-width-down/300?cb=20150825101949') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (4, 'Uchiha Sasuke', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20150110232732/naruto/images/c/c3/Sasuke_headshot.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (5, 'Gaara', 'Sunagakure', 'http://img3.wikia.nocookie.net/__cb20130910220958/naruto/images/thumb/0/0f/Gaara_Part_II.png/300px-Gaara_Part_II.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (6, 'Killer Bee', 'Kumogakure', 'http://vignette3.wikia.nocookie.net/naruto/images/6/63/Killer_B.png/revision/latest/scale-to-width-down/300?cb=20150917075056') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (7, 'Jiraya', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120925123905/naruto/images/thumb/2/21/Profile_Jiraiya.PNG/300px-Profile_Jiraiya.PNG') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (8, 'Namikaze Minato', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140209115534/naruto/images/thumb/1/1f/Minato_Namikaze.PNG/300px-Minato_Namikaze.PNG') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (9, 'Uchiha Madara', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140724225045/naruto/images/thumb/c/cf/Madara_newshot.png/300px-Madara_newshot.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (10, 'Senju Hashirama', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120915132454/naruto/images/thumb/7/7e/Hashirama_Senju.png/300px-Hashirama_Senju.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (11, 'Might Guy', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150401084456/naruto/images/3/31/Might_Guy.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (12, 'Hyuga Neji', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150123214015/naruto/images/6/63/Neji_Part_2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (13, 'Rock Lee', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20131029112352/naruto/images/thumb/7/7d/Lee_timeskip.png/300px-Lee_timeskip.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (14, 'Uchiha Obito', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20140616090247/naruto/images/thumb/a/a0/Obito_Uchiha2.png/300px-Obito_Uchiha2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (15, 'Kurama', 'Tailed Beast', 'http://img1.wikia.nocookie.net/__cb20140818171718/naruto/images/thumb/7/7b/Kurama2.png/300px-Kurama2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (16, 'Uzumaki Kushina', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20121006054451/naruto/images/thumb/4/4d/Kushina_2.png/300px-Kushina_2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (17, 'Nara Shikamaru', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130917013425/naruto/images/thumb/9/9a/Shikamaru_Nara.png/300px-Shikamaru_Nara.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (18, 'Sarutobi Hiruzen', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20120912121115/naruto/images/thumb/e/e4/Hiruzen_Sarutobi.png/300px-Hiruzen_Sarutobi.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (19, 'Tsunade', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20150108211132/naruto/images/b/b3/Tsunade_infobox2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (20, 'Orochimaru', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/1/14/Orochimaru_Infobox.png/revision/latest/scale-to-width-down/300?cb=20150925223113') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (21, 'Uchicha Itachi', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/b/bb/Itachi.png/revision/latest/scale-to-width-down/300?cb=20150602102445') +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (1, '1', 5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (2, '2.1', 1, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (3, '2.2', 2.5, 1, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (4, '2.3', 1.5, 1.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (5, '3', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (6, '4', 7.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (7, '5', 5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (8, '6', 7.5, 10, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (9, '7', 5, 7.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (10, '8', 2.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (11, '9', 7.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (12, '10', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (13, '11', 5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (14, '12.1', 0.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (15, '12.2', 0.5, 1.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (16, '12.3', 2, 0.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (17, '12.4', 2, 0.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (18, '13.1', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (19, '13.2', 5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (20, '14', 2.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (21, '15.1', 5, 6.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (22, '15.2', 2.5, 3.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (23, '16.1', 6.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (24, '16.2', 3.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (25, '17', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (26, '18', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (29, '19', 7.5, 5, 0) \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index a5bbca0..9222df2 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -1,8 +1,8 @@ - + - javaee7-angular + Negotiation Application @@ -26,13 +26,13 @@ - + -

Java EE - Angular Application

+

Negotiation Application


@@ -44,9 +44,9 @@

Java EE - Angular Application


-
+
-

List Persons

+

List Issues

@@ -54,81 +54,80 @@

List Persons

+ total-items="issues.totalResults" items-per-page="issues.pageSize" + ng-model="issues.currentPage" ng-change="refreshGrid()">
-
- -
-

Add Person

+
+ +
+

Add issue

-
-

Edit Person

+
+

Edit issue

-
+ -
- +
+ - + - + -

Add Name.

-

Name must be at least 2 characters long.

-

Name cannot be longer than 50 characters.

+

Add issue number. Seperate childissue with a '.'.

+

Name cannot be longer than 50 characters.

-
- +
+ - + - + - -

Add Description.

-

Description must be at least 5 characters long.

-

Description cannot be longer than 100 characters.

+ +

Add Image URL.

+

Invalid Image URL.

-
- +
+ - + - -

Add Image URL.

-

Invalid Image URL.

+

Add Image URL.

+

Invalid Image URL.

-
- -
+
+ - +
diff --git a/src/main/webapp/script/person.js b/src/main/webapp/script/issue.js similarity index 63% rename from src/main/webapp/script/person.js rename to src/main/webapp/script/issue.js index 58ecbaa..6b50401 100644 --- a/src/main/webapp/script/person.js +++ b/src/main/webapp/script/issue.js @@ -1,20 +1,22 @@ -var app = angular.module('persons', ['ngResource', 'ngGrid', 'ui.bootstrap']); +var app = angular.module('issues', ['ngResource', 'ngGrid', 'ui.bootstrap']); -// Create a controller with name personsListController to bind to the grid section. -app.controller('personsListController', function ($scope, $rootScope, personService) { +// Create a controller with name issuesListController to bind to the grid section. +app.controller('issuesListController', function ($scope, $rootScope, issueService) { // Initialize required information: sorting, the first page to show and the grid options. $scope.sortInfo = {fields: ['id'], directions: ['asc']}; - $scope.persons = {currentPage: 1}; + $scope.issues = {currentPage: 1}; $scope.gridOptions = { - data: 'persons.list', + data: 'issues.list', useExternalSorting: true, sortInfo: $scope.sortInfo, columnDefs: [ { field: 'id', displayName: 'Id' }, - { field: 'name', displayName: 'Name' }, - { field: 'description', displayName: 'Description' }, + { field: 'issueNum', displayName: 'Issue Number' }, + { field: 'p1Rate', displayName: 'Party 1 Rate' }, + { field: 'p2Rate', displayName: 'Party 2 Rate' }, + { field: 'belongs', displayName: 'Won by party #' }, { field: '', width: 30, cellTemplate: '' } ], @@ -23,33 +25,33 @@ app.controller('personsListController', function ($scope, $rootScope, personServ // Broadcasts an event when a row is selected, to signal the form that it needs to load the row data. afterSelectionChange: function (rowItem) { if (rowItem.selected) { - $rootScope.$broadcast('personSelected', $scope.gridOptions.selectedItems[0].id); + $rootScope.$broadcast('issueSelected', $scope.gridOptions.selectedItems[0].id); } } }; // Refresh the grid, calling the appropriate rest method. $scope.refreshGrid = function () { - var listPersonsArgs = { - page: $scope.persons.currentPage, + var listIssuesArgs = { + page: $scope.issues.currentPage, sortFields: $scope.sortInfo.fields[0], sortDirections: $scope.sortInfo.directions[0] }; - personService.get(listPersonsArgs, function (data) { - $scope.persons = data; + issueService.get(listIssuesArgs, function (data) { + $scope.issues = data; }) }; // Broadcast an event when an element in the grid is deleted. No real deletion is perfomed at this point. $scope.deleteRow = function (row) { - $rootScope.$broadcast('deletePerson', row.entity.id); + $rootScope.$broadcast('deleteIssue', row.entity.id); }; // Watch the sortInfo variable. If changes are detected than we need to refresh the grid. // This also works for the first page access, since we assign the initial sorting in the initialize section. $scope.$watch('sortInfo', function () { - $scope.persons = {currentPage: 1}; + $scope.issues = {currentPage: 1}; $scope.refreshGrid(); }, true); @@ -60,7 +62,7 @@ app.controller('personsListController', function ($scope, $rootScope, personServ $scope.sortInfo = sortInfo; }); - // Picks the event broadcasted when a person is saved or deleted to refresh the grid elements with the most + // Picks the event broadcasted when a issue is saved or deleted to refresh the grid elements with the most // updated information. $scope.$on('refreshGrid', function () { $scope.refreshGrid(); @@ -72,28 +74,25 @@ app.controller('personsListController', function ($scope, $rootScope, personServ }); }); -// Create a controller with name personsFormController to bind to the form section. -app.controller('personsFormController', function ($scope, $rootScope, personService) { +// Create a controller with name issuesFormController to bind to the form section. +app.controller('issuesFormController', function ($scope, $rootScope, issueService) { // Clears the form. Either by clicking the 'Clear' button in the form, or when a successfull save is performed. $scope.clearForm = function () { - $scope.person = null; - // For some reason, I was unable to clear field values with type 'url' if the value is invalid. - // This is a workaroud. Needs proper investigation. - document.getElementById('imageUrl').value = null; + $scope.issue = null; // Resets the form validation state. - $scope.personForm.$setPristine(); + $scope.issueForm.$setPristine(); // Broadcast the event to also clear the grid selection. $rootScope.$broadcast('clear'); }; - // Calls the rest method to save a person. - $scope.updatePerson = function () { - personService.save($scope.person).$promise.then( + // Calls the rest method to save a issue. + $scope.updateIssue = function () { + issueService.save($scope.issue).$promise.then( function () { // Broadcast the event to refresh the grid. $rootScope.$broadcast('refreshGrid'); // Broadcast the event to display a save message. - $rootScope.$broadcast('personSaved'); + $rootScope.$broadcast('issueSaved'); $scope.clearForm(); }, function () { @@ -102,21 +101,21 @@ app.controller('personsFormController', function ($scope, $rootScope, personServ }); }; - // Picks up the event broadcasted when the person is selected from the grid and perform the person load by calling + // Picks up the event broadcasted when the issue is selected from the grid and perform the issue load by calling // the appropiate rest service. - $scope.$on('personSelected', function (event, id) { - $scope.person = personService.get({id: id}); + $scope.$on('issueSelected', function (event, id) { + $scope.issue = issueService.get({id: id}); }); - // Picks us the event broadcasted when the person is deleted from the grid and perform the actual person delete by + // Picks us the event broadcasted when the issue is deleted from the grid and perform the actual issue delete by // calling the appropiate rest service. - $scope.$on('deletePerson', function (event, id) { - personService.delete({id: id}).$promise.then( + $scope.$on('deleteIssue', function (event, id) { + issueService.delete({id: id}).$promise.then( function () { // Broadcast the event to refresh the grid. $rootScope.$broadcast('refreshGrid'); // Broadcast the event to display a delete message. - $rootScope.$broadcast('personDeleted'); + $rootScope.$broadcast('issueDeleted'); $scope.clearForm(); }, function () { @@ -124,19 +123,25 @@ app.controller('personsFormController', function ($scope, $rootScope, personServ $rootScope.$broadcast('error'); }); }); + + + // Clears the form. Either by clicking the 'Clear' button in the form, or when a successfull save is performed. + $scope.resolve = function () { + issueService.get({id: -1}); + }; }); // Create a controller with name alertMessagesController to bind to the feedback messages section. app.controller('alertMessagesController', function ($scope) { // Picks up the event to display a saved message. - $scope.$on('personSaved', function () { + $scope.$on('issueSaved', function () { $scope.alerts = [ { type: 'success', msg: 'Record saved successfully!' } ]; }); // Picks up the event to display a deleted message. - $scope.$on('personDeleted', function () { + $scope.$on('issueDeleted', function () { $scope.alerts = [ { type: 'success', msg: 'Record deleted successfully!' } ]; @@ -154,7 +159,7 @@ app.controller('alertMessagesController', function ($scope) { }; }); -// Service that provides persons operations -app.factory('personService', function ($resource) { - return $resource('resources/persons/:id'); +// Service that provides issues operations +app.factory('issueService', function ($resource) { + return $resource('resources/issues/:id'); });