<commit_before>/*
 * Copyright 2011 <NAME> <<EMAIL>>, <NAME>
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
 * General Public License as published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package scrum.client.project;

import ilarkesto.core.base.Str;
import ilarkesto.core.base.Utl;
import ilarkesto.core.scope.Scope;
import ilarkesto.core.time.Date;
import ilarkesto.gwt.client.Gwt;
import ilarkesto.gwt.client.HyperlinkWidget;
import ilarkesto.gwt.client.editor.AFieldModel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import scrum.client.ScrumGwt;
import scrum.client.admin.Auth;
import scrum.client.admin.User;
import scrum.client.collaboration.ForumSupport;
import scrum.client.common.LabelSupport;
import scrum.client.common.ReferenceSupport;
import scrum.client.common.ShowEntityAction;
import scrum.client.common.ThemesContainer;
import scrum.client.estimation.RequirementEstimationVote;
import scrum.client.impediments.Impediment;
import scrum.client.issues.Issue;
import scrum.client.sprint.Sprint;
import scrum.client.sprint.Task;
import scrum.client.tasks.WhiteboardWidget;

import com.google.gwt.user.client.ui.Widget;

public class Requirement extends GRequirement implements ReferenceSupport, LabelSupport, ForumSupport, ThemesContainer {

	public static final String REFERENCE_PREFIX = "sto";
	public static String[] WORK_ESTIMATION_VALUES = new String[] { "", "0.5", "1", "2", "3", "5", "8", "13", "20",
			"40", "100" };

	private transient EstimationBar estimationBar;
	private transient AFieldModel<String> taskStatusLabelModel;
	private transient AFieldModel<String> themesAsStringModel;
	private transient AFieldModel<String> estimatedWorkWithUnitModel;

	public Requirement(Project project) {
		setProject(project);
		setDirty(true);
	}

	public Requirement(Issue issue) {
		setProject(issue.getProject());
		setLabel(issue.getLabel());
		setDescription(issue.getDescription());
	}

	public Requirement(Map data) {
		super(data);
	}

	public void addTheme(String theme) {
		List<String> themes = getThemes();
		if (!themes.contains(theme)) themes.add(theme);
		setThemes(themes);
	}

	@Override
	public List<String> getAvailableThemes() {
		return getProject().getThemes();
	}

	@Override
	public boolean isThemesEditable() {
		return getLabelModel().isEditable();
	}

	@Override
	public boolean isThemesCreatable() {
		return ScrumGwt.isCurrentUserProductOwner();
	}

	public List<Requirement> getRelatedRequirements() {
		List<Requirement> ret = getProject().getRequirementsByThemes(getThemes());
		ret.remove(this);
		return ret;
	}

	public List<Issue> getRelatedIssues() {
		return getProject().getIssuesByThemes(getThemes());
	}

	public void removeFromSprint() {
		setSprint(null);
		for (Task task : getTasks()) {
			task.setOwner(null);
			task.setBurnedWork(0);
		}
	}

	public boolean isDecidable() {
		if (!isTasksClosed()) return false;
		if (getRejectDate() != null) return false;
		return true;
	}

	public boolean isRejected() {
		if (isClosed()) return false;
		if (!isTasksClosed()) return false;
		if (!isInCurrentSprint()) return false;
		return getRejectDate() != null;
	}

	public void reject() {
		setRejectDate(Date.today());
	}

	public void fix() {
		setRejectDate(null);
	}

	public String getEstimatedWorkAsString() {
		return ScrumGwt.getEstimationAsString(getEstimatedWork());
	}

	public String getEstimatedWorkWithUnit() {
		return ScrumGwt.getEstimationAsString(getEstimatedWork(), getProject().getEffortUnit());
	}

	public List<RequirementEstimationVote> getEstimationVotes() {
		return getDao().getRequirementEstimationVotesByRequirement(this);<commit_msg>iss472 mark story as completed if all tasks (at least one) are closed<commit_after>/*
 * Copyright 2011 <NAME> <<EMAIL>>, <NAME>
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
 * General Public License as published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package scrum.client.project;

import ilarkesto.core.base.Str;
import ilarkesto.core.base.Utl;
import ilarkesto.core.scope.Scope;
import ilarkesto.core.time.Date;
import ilarkesto.gwt.client.Gwt;
import ilarkesto.gwt.client.HyperlinkWidget;
import ilarkesto.gwt.client.editor.AFieldModel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import scrum.client.ScrumGwt;
import scrum.client.admin.Auth;
import scrum.client.admin.User;
import scrum.client.collaboration.ForumSupport;
import scrum.client.common.LabelSupport;
import scrum.client.common.ReferenceSupport;
import scrum.client.common.ShowEntityAction;
import scrum.client.common.ThemesContainer;
import scrum.client.estimation.RequirementEstimationVote;
import scrum.client.impediments.Impediment;
import scrum.client.issues.Issue;
import scrum.client.sprint.Sprint;
import scrum.client.sprint.Task;
import scrum.client.tasks.WhiteboardWidget;

import com.google.gwt.user.client.ui.Widget;

public class Requirement extends GRequirement implements ReferenceSupport, LabelSupport, ForumSupport, ThemesContainer {

	public static final String REFERENCE_PREFIX = "sto";
	public static String[] WORK_ESTIMATION_VALUES = new String[] { "", "0.5", "1", "2", "3", "5", "8", "13", "20",
			"40", "100" };

	private transient EstimationBar estimationBar;
	private transient AFieldModel<String> taskStatusLabelModel;
	private transient AFieldModel<String> themesAsStringModel;
	private transient AFieldModel<String> estimatedWorkWithUnitModel;

	public Requirement(Project project) {
		setProject(project);
		setDirty(true);
	}

	public Requirement(Issue issue) {
		setProject(issue.getProject());
		setLabel(issue.getLabel());
		setDescription(issue.getDescription());
	}

	public Requirement(Map data) {
		super(data);
	}

	public void addTheme(String theme) {
		List<String> themes = getThemes();
		if (!themes.contains(theme)) themes.add(theme);
		setThemes(themes);
	}

	@Override
	public List<String> getAvailableThemes() {
		return getProject().getThemes();
	}

	@Override
	public boolean isThemesEditable() {
		return getLabelModel().isEditable();
	}

	@Override
	public boolean isThemesCreatable() {
		return ScrumGwt.isCurrentUserProductOwner();
	}

	public List<Requirement> getRelatedRequirements() {
		List<Requirement> ret = getProject().getRequirementsByThemes(getThemes());
		ret.remove(this);
		return ret;
	}

	public List<Issue> getRelatedIssues() {
		return getProject().getIssuesByThemes(getThemes());
	}

	public void removeFromSprint() {
		setSprint(null);
		for (Task task : getTasks()) {
			task.setOwner(null);
			task.setBurnedWork(0);
		}
	}

	public boolean isDecidable() {
		if (getRejectDate() != null) return false;
		return isTasksClosed();
	}

	public boolean isRejected() {
		if (isClosed()) return false;
		if (!isTasksClosed()) return false;
		if (!isInCurrentSprint()) return false;
		return getRejectDate() != null;
	}

	public void reject() {
		setRejectDate(Date.today());
	}

	public void fix() {
		setRejectDate(null);
	}

	public String getEstimatedWorkAsString() {
		return ScrumGwt.getEstimationAsString(getEstimatedWork());
	}

	public String getEstimatedWorkWithUnit() {
		return ScrumGwt.getEstimationAsString(getEstimatedWork(), getProject().getEffortUnit());
	}

	public List<RequirementEstimationVote> getEstimationVotes() {
		return getDao().getRequirementEstimationVotesByRequirement(this);
{'fraction_non_alphanumeric': 0.11019026497023462, 'fraction_numerical': 0.005486167853390919, 'mean_word_length': 5.417977528089888, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4258684', 'n_tokens_mistral': 2798, 'n_tokens_neox': 2620, 'n_words': 681}