Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Planning Poker session items added #10

Open
wants to merge 2 commits into
base: master
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
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<shiro.version>1.2.2</shiro.version>
<slf4j.version>1.7.5</slf4j.version>
<wicket.version>6.6.0</wicket.version>
<ebean.version>3.2.1</ebean.version>
</properties>
<repositories>
<repository>
Expand Down Expand Up @@ -133,9 +134,9 @@
<version>1.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.avaje</groupId>
<artifactId>ebean</artifactId>
<version>2.8.1</version>
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm</artifactId>
<version>${ebean.version}</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
Expand Down Expand Up @@ -241,9 +242,9 @@
</configuration>
</plugin>
<plugin>
<groupId>org.avaje</groupId>
<artifactId>ebean-maven-enhancement-plugin</artifactId>
<version>2.8.1</version>
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm-mavenenhancer</artifactId>
<version>${ebean.version}</version>
<executions>
<execution>
<phase>process-classes</phase>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/lbogdanov/poker/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public final class Constants {
public static final int USER_LAST_NAME_MAX_LENGTH = 128;
public static final int USER_EMAIL_MAX_LENGTH = 254;
public static final int USER_EXTERNAL_ID_MAX_LENGTH = 64;
public static final int ITEM_TITLE_MAX_LENGTH = 128;
public static final int ITEM_DESCRIPTION_MAX_LENGTH = 4096;

public static final String OAUTH_FILTER_URL = "oauth";
public static final String OAUTH_CLBK_FILTER_URL = "oauth-clbk";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,38 @@
*/
package org.lbogdanov.poker.core;

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

import javax.persistence.*;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Ints;


/**
* Represents a time interval stored as a number of minutes, is used to represent an estimate in a Planning Poker game.
* Represents a session item estimate.
*
* @author Alexandra Fomina
*/
public class Duration implements Comparable<Duration> {
@Entity
@Table(name = "ESTIMATES")
@IdClass(EstimatePrimaryKey.class)
public class Estimate implements Serializable {

static final int MINUTES_PER_HOUR = 60;
static final int MINUTES_PER_DAY = MINUTES_PER_HOUR * 8;
static final int MINUTES_PER_WEEK = MINUTES_PER_DAY * 5;

private int minutes;
@ManyToOne
@PrimaryKeyJoinColumn(name = "USER_ID", referencedColumnName = "ID")
private User user;
@ManyToOne
@PrimaryKeyJoinColumn(name = "ITEM_ID", referencedColumnName = "ID")
private Item item;
@Column(name = "ESTIMATE", nullable = false)
private Integer value;

/**
* Parses the given <code>String</code> to a <code>List</code> of <code>Duration</code> objects.
Expand All @@ -46,8 +58,8 @@ public class Duration implements Comparable<Duration> {
* @return the durations represented by the given <code>String</code>
* @throws IllegalArgumentException if the given <code>String</code> doesn't matches syntax
*/
public static List<Duration> parse(String input) {
List<Duration> durations = new ArrayList<Duration>();
public static List<Estimate> parse(String input) {
List<Estimate> durations = new ArrayList<Estimate>();
StringBuilder duration = new StringBuilder();
for (char chr : input.toCharArray()) {
if (Character.isWhitespace(chr) || chr == ',' || chr == ';') {
Expand All @@ -73,7 +85,7 @@ public static List<Duration> parse(String input) {
default:
throw new IllegalArgumentException(duration.toString() + chr);
}
durations.add(new Duration(Integer.parseInt(duration.toString()) * mul));
durations.add(new Estimate(Integer.parseInt(duration.toString()) * mul));
duration.setLength(0);
}
}
Expand All @@ -84,46 +96,106 @@ public static List<Duration> parse(String input) {
}

/**
* Creates a zero valued <code>Duration</code> instance.
* Creates a zero valued <code>Estimate</code> instance.
*/
public Estimate() {
value = 0;
}

/**
* Creates an <code>Estimate</code> instance with a specified value.
*
* @param value the estimate value in minutes
*/
public Estimate(int value) {
setValue(value);
}

/**
* Returns an estimate author.
*
* @return the user
*/
public Duration() {
this(0);
public User getUser() {
return user;
}

/**
* Creates a <code>Duration</code> instance with a specified number of minutes.
* Sets an estimate author.
*
* @param minutes the initial number of minutes, must be non-negative
* @param user the user to set
*/
public Duration(int minutes) {
setMinutes(minutes);
public void setUser(User user) {
this.user = user;
}

/**
* Returns a number of minutes in this time interval.
* Returns an item evaluated by an estimate.
*
* @return the minutes the number of minutes
* @return the item
*/
public int getMinutes() {
return minutes;
public Item getItem() {
return item;
}

/**
* Sets a number of minutes that this time interval has.
* Sets an estimation item.
*
* @param minutes the number of minutes, must be non-negative
* @param item the item to set
*/
public void setItem(Item item) {
this.item = item;
}

/**
* Returns an estimate value.
*
* @return the estimate value
*/
public Integer getValue() {
return value;
}

/**
* Sets an estimate value.
*
* @param value the estimate value to set, must be non-negative
*/
public void setValue(Integer value) {
Preconditions.checkArgument(value >= 0, "Value must be non-negative");
this.value = value;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(getItem(), getUser());
}

/**
* {@inheritDoc}
*/
public void setMinutes(int minutes) {
Preconditions.checkArgument(minutes >= 0, "Value must be non-negative");
this.minutes = minutes;
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Estimate) {
Estimate other = (Estimate) obj;
return Objects.equal(this.getItem(), other.getItem())
&& Objects.equal(this.getUser(), other.getUser());
}
return false;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
int n = minutes;
int n = value;
if (n == 0) {
return "0";
}
Expand All @@ -146,34 +218,4 @@ public String toString() {
return Joiner.on(' ').join(duration);
}

/**
* {@inheritDoc}
*/
@Override
public int compareTo(Duration that) {
return Ints.compare(this.minutes, that.minutes);
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other instanceof Duration) {
return this.getMinutes() == ((Duration) other).getMinutes();
}
return false;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getMinutes();
}

}
68 changes: 68 additions & 0 deletions src/main/java/org/lbogdanov/poker/core/EstimatePrimaryKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.lbogdanov.poker.core;

import java.io.Serializable;

import com.google.common.base.Objects;

/**
* A primary key for {@link Estimate} class.
*
* @author afomina
*/
public class EstimatePrimaryKey implements Serializable {

private User user;
private Item item;

/**
* @return the user
*/
public User getUser() {
return user;
}

/**
* @param user the user to set
*/
public void setUser(User user) {
this.user = user;
}

/**
* @return the item
*/
public Item getItem() {
return item;
}

/**
* @param item the item to set
*/
public void setItem(Item item) {
this.item = item;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(getItem(), getUser());
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof EstimatePrimaryKey) {
EstimatePrimaryKey other = (EstimatePrimaryKey) obj;
return Objects.equal(this.getItem(), other.getItem())
&& Objects.equal(this.getUser(), other.getUser());
}
return false;
}
}
Loading