Added test for BAC value.
Code refactoring. (cherry picked from commit 0f00d11)
This commit is contained in:
parent
0763cbfe02
commit
529d3b738e
75 changed files with 2235 additions and 2585 deletions
|
|
@ -33,11 +33,10 @@ import org.zkoss.zk.ui.event.Event;
|
|||
|
||||
public class CommandOnTaskContextualized<T> {
|
||||
|
||||
public static <T> CommandOnTaskContextualized<T> create(
|
||||
ICommandOnTask<T> commandOnTask, IDomainAndBeansMapper<T> mapper,
|
||||
IContext<T> context) {
|
||||
return new CommandOnTaskContextualized<T>(commandOnTask, mapper,
|
||||
context);
|
||||
public static <T> CommandOnTaskContextualized<T> create(ICommandOnTask<T> commandOnTask,
|
||||
IDomainAndBeansMapper<T> mapper, IContext<T> context) {
|
||||
|
||||
return new CommandOnTaskContextualized<T>(commandOnTask, mapper, context);
|
||||
}
|
||||
|
||||
private final ICommandOnTask<T> commandOnTask;
|
||||
|
|
@ -46,16 +45,17 @@ public class CommandOnTaskContextualized<T> {
|
|||
|
||||
private final IDomainAndBeansMapper<T> mapper;
|
||||
|
||||
private CommandOnTaskContextualized(ICommandOnTask<T> commandOnTask,
|
||||
IDomainAndBeansMapper<T> mapper, IContext<T> context) {
|
||||
private CommandOnTaskContextualized(ICommandOnTask<T> commandOnTask, IDomainAndBeansMapper<T> mapper,
|
||||
IContext<T> context) {
|
||||
this.commandOnTask = commandOnTask;
|
||||
this.mapper = mapper;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void doAction(TaskComponent taskComponent) {
|
||||
doAction(ContextRelativeToOtherComponent.makeRelativeTo(context,
|
||||
taskComponent), domainObjectFor(taskComponent.getTask()));
|
||||
doAction(
|
||||
ContextRelativeToOtherComponent.makeRelativeTo(context, taskComponent),
|
||||
domainObjectFor(taskComponent.getTask()));
|
||||
}
|
||||
|
||||
public void doAction(Task task) {
|
||||
|
|
@ -67,8 +67,9 @@ public class CommandOnTaskContextualized<T> {
|
|||
}
|
||||
|
||||
private void doAction(IContext<T> context, T domainObject) {
|
||||
IContextWithPlannerTask<T> contextWithTask = ContextWithPlannerTask
|
||||
.create(context, mapper.findAssociatedBean(domainObject));
|
||||
IContextWithPlannerTask<T> contextWithTask =
|
||||
ContextWithPlannerTask.create(context, mapper.findAssociatedBean(domainObject));
|
||||
|
||||
commandOnTask.doAction(contextWithTask, domainObject);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,8 +119,7 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return result;
|
||||
}
|
||||
|
||||
public List<DependencyComponent> asDependencyComponents(
|
||||
Collection<? extends Dependency> dependencies) {
|
||||
public List<DependencyComponent> asDependencyComponents(Collection<? extends Dependency> dependencies) {
|
||||
List<DependencyComponent> result = new ArrayList<DependencyComponent>();
|
||||
for (Dependency dependency : dependencies) {
|
||||
result.add(new DependencyComponent(taskComponentByTask
|
||||
|
|
@ -134,13 +133,12 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return asDependencyComponents(Arrays.asList(dependency)).get(0);
|
||||
}
|
||||
|
||||
private synchronized void addTaskComponent(TaskRow beforeThis,
|
||||
final TaskComponent taskComponent, boolean relocate) {
|
||||
private synchronized void addTaskComponent(TaskRow beforeThis, final TaskComponent taskComponent, boolean relocate) {
|
||||
insertBefore(taskComponent.getRow(), beforeThis);
|
||||
addContextMenu(taskComponent);
|
||||
addListenerForTaskComponentEditForm(taskComponent);
|
||||
taskComponent.afterCompose();
|
||||
if (relocate) {
|
||||
if ( relocate ) {
|
||||
getGanttPanel().adjustZoomColumnsHeight();
|
||||
}
|
||||
}
|
||||
|
|
@ -168,9 +166,8 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void addListenerForTaskComponentEditForm(
|
||||
final TaskComponent taskComponent) {
|
||||
if (doubleClickCommand == null) {
|
||||
private void addListenerForTaskComponentEditForm(final TaskComponent taskComponent) {
|
||||
if ( doubleClickCommand == null ) {
|
||||
return;
|
||||
}
|
||||
taskComponent.addEventListener("onDoubleClick", new EventListener() {
|
||||
|
|
@ -292,25 +289,23 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
private Map<TaskComponent, Menupopup> contextMenus = new HashMap<TaskComponent, Menupopup>();
|
||||
|
||||
private Menupopup getContextMenuFor(TaskComponent taskComponent) {
|
||||
if (contextMenus.get(taskComponent) == null) {
|
||||
MenuBuilder<TaskComponent> menuBuilder = MenuBuilder.on(getPage(),
|
||||
getTaskComponents());
|
||||
if (disabilityConfiguration.isAddingDependenciesEnabled()) {
|
||||
menuBuilder.item(_("Add Dependency"),
|
||||
"/common/img/ico_dependency.png",
|
||||
if ( contextMenus.get(taskComponent) == null ) {
|
||||
MenuBuilder<TaskComponent> menuBuilder = MenuBuilder.on(getPage(), getTaskComponents());
|
||||
|
||||
if ( disabilityConfiguration.isAddingDependenciesEnabled() ) {
|
||||
menuBuilder.item(_("Add Dependency"), "/common/img/ico_dependency.png",
|
||||
new ItemAction<TaskComponent>() {
|
||||
|
||||
@Override
|
||||
public void onEvent(TaskComponent choosen,
|
||||
Event event) {
|
||||
public void onEvent(TaskComponent choosen, Event event) {
|
||||
choosen.addDependency();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (CommandOnTaskContextualized<?> command : commandsOnTasksContextualized) {
|
||||
if (command.accepts(taskComponent)) {
|
||||
menuBuilder.item(command.getName(), command.getIcon(),
|
||||
command.toItemAction());
|
||||
if ( command.accepts(taskComponent) ) {
|
||||
menuBuilder.item(command.getName(), command.getIcon(), command.toItemAction());
|
||||
}
|
||||
}
|
||||
Menupopup result = menuBuilder.createWithoutSettingContext();
|
||||
|
|
@ -358,22 +353,21 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
getGanttPanel().getDependencyList().redrawDependencies();
|
||||
}
|
||||
|
||||
private void reload(List<Task> tasks, List<Task> tasksPendingToAdd,
|
||||
boolean relocate) {
|
||||
private void reload(List<Task> tasks, List<Task> tasksPendingToAdd, boolean relocate) {
|
||||
for (Task task : tasks) {
|
||||
if (visibleTasks.contains(task)) {
|
||||
addPendingTasks(tasksPendingToAdd, rowFor(task),
|
||||
relocate);
|
||||
if ( visibleTasks.contains(task) ) {
|
||||
addPendingTasks(tasksPendingToAdd, rowFor(task), relocate);
|
||||
}
|
||||
final boolean isShown = visibleTasks.contains(task);
|
||||
if (predicate.accepts(task) != isShown) {
|
||||
if (isShown) {
|
||||
|
||||
if ( predicate.accepts(task) != isShown ) {
|
||||
if ( isShown ) {
|
||||
makeDisappear(task);
|
||||
} else {
|
||||
tasksPendingToAdd.add(task);
|
||||
}
|
||||
}
|
||||
if (task instanceof TaskContainer) {
|
||||
if ( task instanceof TaskContainer ) {
|
||||
reload(task.getTasks(), tasksPendingToAdd, relocate);
|
||||
}
|
||||
}
|
||||
|
|
@ -391,9 +385,8 @@ public class TaskList extends XulElement implements AfterCompose {
|
|||
return taskComponent == null ? null : taskComponent.getRow();
|
||||
}
|
||||
|
||||
private void addPendingTasks(List<Task> tasksPendingToAdd,
|
||||
TaskRow insertBefore, boolean relocate) {
|
||||
if (tasksPendingToAdd.isEmpty()) {
|
||||
private void addPendingTasks(List<Task> tasksPendingToAdd, TaskRow insertBefore, boolean relocate) {
|
||||
if ( tasksPendingToAdd.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
for (TaskComponent each : createAndPublishComponentsIfNeeded(tasksPendingToAdd)) {
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ package org.libreplan.business;
|
|||
*/
|
||||
public class BusinessGlobalNames {
|
||||
|
||||
public final static String BUSINESS_SPRING_CONFIG_FILE =
|
||||
"classpath:/libreplan-business-spring-config.xml";
|
||||
public final static String BUSINESS_SPRING_CONFIG_FILE = "classpath:/libreplan-business-spring-config.xml";
|
||||
|
||||
private BusinessGlobalNames () {}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,30 +28,22 @@ import org.libreplan.business.common.Registry;
|
|||
|
||||
public enum PredefinedAdvancedTypes {
|
||||
|
||||
CHILDREN("children", new BigDecimal(100), new BigDecimal(0.01), true,
|
||||
false),
|
||||
PERCENTAGE(
|
||||
"percentage", new BigDecimal(100), new BigDecimal(0.01), true,
|
||||
false),
|
||||
UNITS("units", new BigDecimal(Integer.MAX_VALUE),
|
||||
new BigDecimal(1), false, false),
|
||||
SUBCONTRACTOR("subcontractor",
|
||||
new BigDecimal(100), new BigDecimal(0.01), true, false),
|
||||
TIMESHEETS("timesheets",
|
||||
new BigDecimal(100), new BigDecimal(0.01), true, false, true);
|
||||
CHILDREN("children", new BigDecimal(100), new BigDecimal(0.01), true, false),
|
||||
PERCENTAGE("percentage", new BigDecimal(100), new BigDecimal(0.01), true, false),
|
||||
UNITS("units", new BigDecimal(Integer.MAX_VALUE), new BigDecimal(1), false, false),
|
||||
SUBCONTRACTOR("subcontractor", new BigDecimal(100), new BigDecimal(0.01), true, false),
|
||||
TIMESHEETS("timesheets", new BigDecimal(100), new BigDecimal(0.01), true, false, true);
|
||||
|
||||
|
||||
private PredefinedAdvancedTypes(String name, BigDecimal defaultMaxValue,
|
||||
BigDecimal precision, boolean percentage, boolean qualityForm) {
|
||||
private PredefinedAdvancedTypes(String name, BigDecimal defaultMaxValue, BigDecimal precision, boolean percentage,
|
||||
boolean qualityForm) {
|
||||
this(name, defaultMaxValue, precision, percentage, qualityForm, false);
|
||||
}
|
||||
|
||||
private PredefinedAdvancedTypes(String name, BigDecimal defaultMaxValue,
|
||||
BigDecimal precision, boolean percentage, boolean qualityForm,
|
||||
boolean readOnly) {
|
||||
private PredefinedAdvancedTypes(String name, BigDecimal defaultMaxValue, BigDecimal precision, boolean percentage,
|
||||
boolean qualityForm, boolean readOnly) {
|
||||
this.name = name;
|
||||
this.defaultMaxValue = defaultMaxValue.setScale(4,
|
||||
BigDecimal.ROUND_HALF_UP);
|
||||
this.defaultMaxValue = defaultMaxValue.setScale(4, BigDecimal.ROUND_HALF_UP);
|
||||
this.unitPrecision = precision.setScale(4, BigDecimal.ROUND_HALF_UP);
|
||||
this.percentage = percentage;
|
||||
this.qualityForm = qualityForm;
|
||||
|
|
@ -71,8 +63,10 @@ public enum PredefinedAdvancedTypes {
|
|||
private final boolean readOnly;
|
||||
|
||||
public AdvanceType createType() {
|
||||
AdvanceType advanceType = AdvanceType.create(name, defaultMaxValue,
|
||||
false, unitPrecision, true, percentage, qualityForm);
|
||||
|
||||
AdvanceType advanceType =
|
||||
AdvanceType.create(name, defaultMaxValue, false, unitPrecision, true, percentage, qualityForm);
|
||||
|
||||
advanceType.setReadOnly(readOnly);
|
||||
return advanceType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
||||
implements IBaseCalendarDAO {
|
||||
public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar> implements IBaseCalendarDAO {
|
||||
|
||||
@Override
|
||||
public List<BaseCalendar> getBaseCalendars() {
|
||||
|
|
@ -65,10 +64,9 @@ public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
|||
}
|
||||
|
||||
private void removeResourceCalendarInstances(List<BaseCalendar> list) {
|
||||
for (Iterator<BaseCalendar> iterator = list.iterator(); iterator
|
||||
.hasNext();) {
|
||||
for (Iterator<BaseCalendar> iterator = list.iterator(); iterator.hasNext();) {
|
||||
BaseCalendar baseCalendar = iterator.next();
|
||||
if (baseCalendar instanceof ResourceCalendar) {
|
||||
if ( baseCalendar instanceof ResourceCalendar ) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,9 @@ import org.libreplan.business.workingday.ResourcesPerDay;
|
|||
* some exceptions of its parent calendar.
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class BaseCalendar extends IntegrationEntity implements ICalendar,
|
||||
IHumanIdentifiable, Comparable<BaseCalendar> {
|
||||
public class BaseCalendar extends IntegrationEntity implements ICalendar, IHumanIdentifiable, Comparable<BaseCalendar> {
|
||||
|
||||
private static final Capacity DEFAULT_VALUE = Capacity.zero()
|
||||
.overAssignableWithoutLimit();
|
||||
private static final Capacity DEFAULT_VALUE = Capacity.zero().overAssignableWithoutLimit();
|
||||
|
||||
public static BaseCalendar create() {
|
||||
return create(new BaseCalendar(CalendarData.create()));
|
||||
|
|
@ -84,7 +82,7 @@ public class BaseCalendar extends IntegrationEntity implements ICalendar,
|
|||
|
||||
private static void resetDefaultCapacities(BaseCalendar calendar) {
|
||||
CalendarData calendarData = calendar.getLastCalendarData();
|
||||
if (calendarData != null) {
|
||||
if ( calendarData != null ) {
|
||||
CalendarData.resetDefaultCapacities(calendarData);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public abstract class BaseEntity implements INewObject {
|
|||
Collection<? extends T> entities) {
|
||||
Map<Long, Set<T>> result = new HashMap<Long, Set<T>>();
|
||||
for (T each : entities) {
|
||||
if (!result.containsKey(each.getId())) {
|
||||
if ( !result.containsKey(each.getId()) ) {
|
||||
result.put(each.getId(), new HashSet<T>());
|
||||
}
|
||||
result.get(each.getId()).add(each);
|
||||
|
|
@ -71,8 +71,7 @@ public abstract class BaseEntity implements INewObject {
|
|||
|
||||
private static final Log LOG = LogFactory.getLog(BaseEntity.class);
|
||||
|
||||
private static final ValidatorFactory validatorFactory = Validation
|
||||
.buildDefaultValidatorFactory();
|
||||
private static final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
|
||||
|
||||
private static final Validator validator = validatorFactory.getValidator();
|
||||
|
||||
|
|
@ -134,9 +133,8 @@ public abstract class BaseEntity implements INewObject {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void validate() throws ValidationException {
|
||||
Set<ConstraintViolation<BaseEntity>> violations = validator
|
||||
.validate(this);
|
||||
if (!violations.isEmpty()) {
|
||||
Set<ConstraintViolation<BaseEntity>> violations = validator.validate(this);
|
||||
if ( !violations.isEmpty() ) {
|
||||
throw new ValidationException(violations);
|
||||
}
|
||||
}
|
||||
|
|
@ -153,8 +151,7 @@ public abstract class BaseEntity implements INewObject {
|
|||
}
|
||||
|
||||
public String getExtraInformation() {
|
||||
return "[ id: " + getId() + ", newObject: "
|
||||
+ isNewObject() + "]";
|
||||
return "[ id: " + getId() + ", newObject: " + isNewObject() + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class Flagged<T, F> {
|
|||
|
||||
public boolean isFlaggedWithSomeOf(F... flags) {
|
||||
for (F each : flags) {
|
||||
if (this.isFlaggedWith(each)) {
|
||||
if ( this.isFlaggedWith(each) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,13 +38,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class ConfigurationDAO extends GenericDAOHibernate<Configuration, Long>
|
||||
implements IConfigurationDAO {
|
||||
public class ConfigurationDAO extends GenericDAOHibernate<Configuration, Long> implements IConfigurationDAO {
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
List<Configuration> list = list(Configuration.class);
|
||||
if (list.isEmpty()) {
|
||||
if ( list.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
|
|
@ -59,10 +58,8 @@ public class ConfigurationDAO extends GenericDAOHibernate<Configuration, Long>
|
|||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void saveChangedDefaultPassword(String user, boolean change) {
|
||||
user = user.substring(0, 1).toUpperCase()
|
||||
+ user.substring(1).toLowerCase();
|
||||
String sql = "UPDATE Configuration e SET e.changedDefault" + user
|
||||
+ "Password = :change";
|
||||
user = user.substring(0, 1).toUpperCase() + user.substring(1).toLowerCase();
|
||||
String sql = "UPDATE Configuration e SET e.changedDefault" + user + "Password = :change";
|
||||
Query query = getSession().createQuery(sql);
|
||||
query.setParameter("change", change);
|
||||
query.executeUpdate();
|
||||
|
|
|
|||
|
|
@ -58,8 +58,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @param <PK>
|
||||
* Primary key class
|
||||
*/
|
||||
public class GenericDAOHibernate<E extends BaseEntity,
|
||||
PK extends Serializable> implements IGenericDAO<E, PK> {
|
||||
public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable> implements IGenericDAO<E, PK> {
|
||||
|
||||
private Class<E> entityClass;
|
||||
|
||||
|
|
@ -68,8 +67,8 @@ public class GenericDAOHibernate<E extends BaseEntity,
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public GenericDAOHibernate() {
|
||||
this.entityClass = (Class<E>) ((ParameterizedType) getClass()
|
||||
.getGenericSuperclass()).getActualTypeArguments()[0];
|
||||
this.entityClass =
|
||||
(Class<E>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
public GenericDAOHibernate(Class<E> entityClass) {
|
||||
|
|
@ -101,7 +100,7 @@ public class GenericDAOHibernate<E extends BaseEntity,
|
|||
}
|
||||
|
||||
public void reattachUnmodifiedEntity(E entity) {
|
||||
if (Hibernate.isInitialized(entity) && entity.isNewObject()) {
|
||||
if ( Hibernate.isInitialized(entity) && entity.isNewObject() ) {
|
||||
return;
|
||||
}
|
||||
getSession().lock(entity, LockMode.NONE);
|
||||
|
|
@ -125,14 +124,14 @@ public class GenericDAOHibernate<E extends BaseEntity,
|
|||
Method getIdMethod = entityClass.getMethod("getId");
|
||||
id = (Serializable) getIdMethod.invoke(entity);
|
||||
|
||||
if (id == null) {
|
||||
if ( id == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method getVersionMethod = entityClass.getMethod("getVersion");
|
||||
versionValueInMemory = (Long) getVersionMethod.invoke(entity);
|
||||
|
||||
if (versionValueInMemory == null) {
|
||||
if ( versionValueInMemory == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -142,14 +141,14 @@ public class GenericDAOHibernate<E extends BaseEntity,
|
|||
|
||||
/* Check version. */
|
||||
Long versionValueInDB = (Long) getSession().createCriteria(entityClass)
|
||||
.add(Restrictions.idEq(id)).setProjection(
|
||||
Projections.property("version")).uniqueResult();
|
||||
.add(Restrictions.idEq(id))
|
||||
.setProjection(Projections.property("version")).uniqueResult();
|
||||
|
||||
if (versionValueInDB == null) {
|
||||
if ( versionValueInDB == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!versionValueInMemory.equals(versionValueInDB)) {
|
||||
if ( !versionValueInMemory.equals(versionValueInDB) ) {
|
||||
throw new StaleObjectStateException(entityClass.getName(), id);
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +170,7 @@ public class GenericDAOHibernate<E extends BaseEntity,
|
|||
|
||||
E entity = (E) getSession().get(entityClass, id);
|
||||
|
||||
if (entity == null) {
|
||||
if ( entity == null ) {
|
||||
throw new InstanceNotFoundException(id, entityClass.getName());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,8 +47,7 @@ import org.libreplan.business.resources.entities.Criterion;
|
|||
import org.libreplan.business.resources.entities.ResourceEnum;
|
||||
import org.libreplan.business.templates.entities.OrderLineTemplate;
|
||||
|
||||
public class HoursGroup extends IntegrationEntity implements Cloneable,
|
||||
ICriterionRequirable {
|
||||
public class HoursGroup extends IntegrationEntity implements Cloneable, ICriterionRequirable {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(HoursGroup.class);
|
||||
|
||||
|
|
@ -197,22 +196,19 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
* if the new sum of percentages in the parent {@link OrderLine}
|
||||
* surpasses one
|
||||
*/
|
||||
public void setPercentage(BigDecimal proportion)
|
||||
throws IllegalArgumentException {
|
||||
public void setPercentage(BigDecimal proportion) throws IllegalArgumentException {
|
||||
BigDecimal oldPercentage = this.percentage;
|
||||
|
||||
this.percentage = proportion;
|
||||
|
||||
if (!isPercentageValidForParent()) {
|
||||
if ( !isPercentageValidForParent() ) {
|
||||
this.percentage = oldPercentage;
|
||||
throw new IllegalArgumentException(
|
||||
_("Total percentage should be less than 100%"));
|
||||
throw new IllegalArgumentException(_("Total percentage should be less than 100%"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPercentageValidForParent() {
|
||||
return (parentOrderLine != null) ? parentOrderLine.isPercentageValid()
|
||||
: orderLineTemplate.isPercentageValid();
|
||||
return (parentOrderLine != null) ? parentOrderLine.isPercentageValid() : orderLineTemplate.isPercentageValid();
|
||||
}
|
||||
|
||||
public BigDecimal getPercentage() {
|
||||
|
|
@ -243,7 +239,7 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
criterions.add(criterionRequirement.getCriterion());
|
||||
}
|
||||
for (IndirectCriterionRequirement requirement : getIndirectCriterionRequirement()) {
|
||||
if (requirement.isValid()) {
|
||||
if ( requirement.isValid() ) {
|
||||
criterions.add(requirement.getCriterion());
|
||||
}
|
||||
}
|
||||
|
|
@ -252,11 +248,11 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
|
||||
@Override
|
||||
public void addCriterionRequirement(CriterionRequirement requirement) {
|
||||
if (!isValidResourceType(requirement)) {
|
||||
if ( !isValidResourceType(requirement) ) {
|
||||
throw new IllegalStateException(
|
||||
"Criterion cannot be assigned to this Hours Group. Criterion Resource Type is of a different type");
|
||||
}
|
||||
if (existSameCriterionRequirement(requirement)) {
|
||||
if ( existSameCriterionRequirement(requirement) ) {
|
||||
throw new IllegalStateException(
|
||||
"Criterion cannot be assigned to this Hours Group. Criterion already exist within Hours Group");
|
||||
|
||||
|
|
@ -265,10 +261,8 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
criterionRequirements.add(requirement);
|
||||
}
|
||||
|
||||
public boolean canAddCriterionRequirement(
|
||||
CriterionRequirement newRequirement) {
|
||||
if ((isValidResourceType(newRequirement))
|
||||
&& (!existSameCriterionRequirement(newRequirement))) {
|
||||
public boolean canAddCriterionRequirement(CriterionRequirement newRequirement) {
|
||||
if ( (isValidResourceType(newRequirement)) && (!existSameCriterionRequirement(newRequirement)) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -277,10 +271,8 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
@Override
|
||||
public void removeCriterionRequirement(CriterionRequirement requirement) {
|
||||
criterionRequirements.remove(requirement);
|
||||
if (requirement instanceof IndirectCriterionRequirement) {
|
||||
((IndirectCriterionRequirement) requirement).getParent()
|
||||
.getChildren().remove(
|
||||
(IndirectCriterionRequirement) requirement);
|
||||
if ( requirement instanceof IndirectCriterionRequirement ) {
|
||||
((IndirectCriterionRequirement) requirement).getParent().getChildren().remove(requirement);
|
||||
}
|
||||
requirement.setCriterion(null);
|
||||
requirement.setHoursGroup(null);
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ public class Order extends OrderLineGroup implements Comparable {
|
|||
|
||||
for (OrderElement orderElement : getAllChildren()) {
|
||||
TaskElement taskElement = orderElement.getAssociatedTaskElement();
|
||||
if (taskElement != null) {
|
||||
if ( taskElement != null ) {
|
||||
result.add(taskElement);
|
||||
}
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ public class Order extends OrderLineGroup implements Comparable {
|
|||
public List<TaskElement> getAssociatedTasks() {
|
||||
ArrayList<TaskElement> result = new ArrayList<TaskElement>();
|
||||
TaskGroup taskGroup = getAssociatedTaskElement();
|
||||
if (taskGroup != null) {
|
||||
if ( taskGroup != null ) {
|
||||
result.addAll(taskGroup.getChildren());
|
||||
}
|
||||
return result;
|
||||
|
|
@ -353,15 +353,13 @@ public class Order extends OrderLineGroup implements Comparable {
|
|||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "the project must have a start date")
|
||||
private boolean isIfSchedulingModeIsForwardOrderMustHaveStartDateConstraint() {
|
||||
return getSchedulingMode() != SchedulingMode.FORWARD
|
||||
|| getInitDate() != null;
|
||||
return getSchedulingMode() != SchedulingMode.FORWARD || getInitDate() != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "the project must have a deadline")
|
||||
private boolean isIfSchedulingModeIsBackwardsOrderMustHaveDeadlineConstraint() {
|
||||
return getSchedulingMode() != SchedulingMode.BACKWARDS
|
||||
|| getDeadline() != null;
|
||||
return getSchedulingMode() != SchedulingMode.BACKWARDS || getDeadline() != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
private SchedulingDataForVersion.Data current = null;
|
||||
|
||||
public SchedulingDataForVersion.Data getCurrentSchedulingData() {
|
||||
if (current == null) {
|
||||
if ( current == null ) {
|
||||
throw new IllegalStateException(
|
||||
"in order to use scheduling state related data "
|
||||
+ "useSchedulingDataFor(OrderVersion orderVersion) "
|
||||
|
|
@ -151,19 +151,15 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
return current;
|
||||
}
|
||||
|
||||
private void schedulingDataNowPointsTo(DeepCopy deepCopy,
|
||||
OrderVersion version) {
|
||||
current = getCurrentSchedulingData().pointsTo(deepCopy, version,
|
||||
schedulingVersionFor(version));
|
||||
private void schedulingDataNowPointsTo(DeepCopy deepCopy, OrderVersion version) {
|
||||
current = getCurrentSchedulingData().pointsTo(deepCopy, version, schedulingVersionFor(version));
|
||||
for (OrderElement each : getChildren()) {
|
||||
each.schedulingDataNowPointsTo(deepCopy, version);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addNeededReplaces(DeepCopy deepCopy,
|
||||
OrderVersion newOrderVersion) {
|
||||
SchedulingDataForVersion currentVersion = getCurrentSchedulingData()
|
||||
.getVersion();
|
||||
protected void addNeededReplaces(DeepCopy deepCopy, OrderVersion newOrderVersion) {
|
||||
SchedulingDataForVersion currentVersion = getCurrentSchedulingData().getVersion();
|
||||
SchedulingDataForVersion newSchedulingVersion = schedulingVersionFor(newOrderVersion);
|
||||
deepCopy.replace(currentVersion, newSchedulingVersion);
|
||||
for (OrderElement each : getChildren()) {
|
||||
|
|
@ -172,7 +168,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
}
|
||||
|
||||
public SchedulingState getSchedulingState() {
|
||||
if (schedulingState == null) {
|
||||
if ( schedulingState == null ) {
|
||||
ensureSchedulingStateInitializedFromTop();
|
||||
initializeSchedulingState(); // maybe this order element was added
|
||||
// later
|
||||
|
|
@ -189,11 +185,10 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
}
|
||||
|
||||
private SchedulingState initializeSchedulingState() {
|
||||
if (schedulingState != null) {
|
||||
if ( schedulingState != null ) {
|
||||
return schedulingState;
|
||||
}
|
||||
return schedulingState = SchedulingState.createSchedulingState(
|
||||
getSchedulingStateType(), getChildrenStates(),
|
||||
return schedulingState = SchedulingState.createSchedulingState(getSchedulingStateType(), getChildrenStates(),
|
||||
getCurrentSchedulingData().onTypeChangeListener());
|
||||
}
|
||||
|
||||
|
|
@ -227,11 +222,10 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
useSchedulingDataFor(orderVersion, true);
|
||||
}
|
||||
|
||||
public void useSchedulingDataFor(OrderVersion orderVersion,
|
||||
boolean recursive) {
|
||||
public void useSchedulingDataFor(OrderVersion orderVersion, boolean recursive) {
|
||||
Validate.notNull(orderVersion);
|
||||
SchedulingDataForVersion schedulingVersion = schedulingVersionFor(orderVersion);
|
||||
if (recursive) {
|
||||
if ( recursive ) {
|
||||
for (OrderElement each : getChildren()) {
|
||||
each.useSchedulingDataFor(orderVersion);
|
||||
}
|
||||
|
|
@ -520,7 +514,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
}
|
||||
|
||||
public TaskElement getAssociatedTaskElement() {
|
||||
if (getTaskSource() == null) {
|
||||
if ( getTaskSource() == null ) {
|
||||
return null;
|
||||
} else {
|
||||
return getTaskSource().getTask();
|
||||
|
|
@ -541,7 +535,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (name != null && name.length() > 255) {
|
||||
if ( name != null && name.length() > 255 ) {
|
||||
name = name.substring(0, 255);
|
||||
}
|
||||
this.getInfoComponent().setName(name);
|
||||
|
|
@ -718,32 +712,28 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
* @throws DuplicateValueTrueReportGlobalAdvanceException
|
||||
* @throws DuplicateAdvanceAssignmentForOrderElementException
|
||||
*/
|
||||
public void addAdvanceAssignment(
|
||||
DirectAdvanceAssignment newAdvanceAssignment)
|
||||
throws DuplicateValueTrueReportGlobalAdvanceException,
|
||||
DuplicateAdvanceAssignmentForOrderElementException {
|
||||
checkNoOtherGlobalAdvanceAssignment(newAdvanceAssignment);
|
||||
checkAncestorsNoOtherAssignmentWithSameAdvanceType(this,
|
||||
newAdvanceAssignment);
|
||||
checkChildrenNoOtherAssignmentWithSameAdvanceType(this,
|
||||
newAdvanceAssignment);
|
||||
public void addAdvanceAssignment(DirectAdvanceAssignment newAdvanceAssignment)
|
||||
throws DuplicateValueTrueReportGlobalAdvanceException, DuplicateAdvanceAssignmentForOrderElementException {
|
||||
|
||||
if (getReportGlobalAdvanceAssignment() == null) {
|
||||
checkNoOtherGlobalAdvanceAssignment(newAdvanceAssignment);
|
||||
checkAncestorsNoOtherAssignmentWithSameAdvanceType(this, newAdvanceAssignment);
|
||||
checkChildrenNoOtherAssignmentWithSameAdvanceType(this, newAdvanceAssignment);
|
||||
|
||||
if ( getReportGlobalAdvanceAssignment() == null ) {
|
||||
newAdvanceAssignment.setReportGlobalAdvance(true);
|
||||
}
|
||||
|
||||
newAdvanceAssignment.setOrderElement(this);
|
||||
this.directAdvanceAssignments.add(newAdvanceAssignment);
|
||||
|
||||
if (this.getParent() != null) {
|
||||
if ( this.getParent() != null ) {
|
||||
addChildrenAdvanceInParents(this.getParent());
|
||||
this.getParent().addIndirectAdvanceAssignment(
|
||||
newAdvanceAssignment.createIndirectAdvanceFor(this.getParent()));
|
||||
this.getParent().addIndirectAdvanceAssignment(newAdvanceAssignment.createIndirectAdvanceFor(this.getParent()));
|
||||
}
|
||||
}
|
||||
|
||||
public void addChildrenAdvanceInParents(OrderLineGroup parent) {
|
||||
if ((parent != null) && (!parent.existChildrenAdvance())) {
|
||||
if ( (parent != null) && (!parent.existChildrenAdvance()) ) {
|
||||
parent.addChildrenAdvanceOrderLineGroup();
|
||||
addChildrenAdvanceInParents(parent.getParent());
|
||||
}
|
||||
|
|
@ -751,7 +741,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
}
|
||||
|
||||
public void removeChildrenAdvanceInParents(OrderLineGroup parent) {
|
||||
if ((parent != null) && (parent.existChildrenAdvance())
|
||||
if ( (parent != null) && (parent.existChildrenAdvance() )
|
||||
&& (!itsChildsHasAdvances(parent))) {
|
||||
parent.removeChildrenAdvanceOrderLineGroup();
|
||||
removeChildrenAdvanceInParents(parent.getParent());
|
||||
|
|
@ -760,25 +750,26 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
|
||||
private boolean itsChildsHasAdvances(OrderElement orderElement) {
|
||||
for (OrderElement child : orderElement.getChildren()) {
|
||||
if ((!child.getIndirectAdvanceAssignments().isEmpty())
|
||||
|| (!child.getDirectAdvanceAssignments().isEmpty())) {
|
||||
|
||||
if ( (!child.getIndirectAdvanceAssignments().isEmpty()) ||
|
||||
(!child.getDirectAdvanceAssignments().isEmpty()) ) {
|
||||
return true;
|
||||
}
|
||||
if (itsChildsHasAdvances(child)) {
|
||||
if ( itsChildsHasAdvances(child) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void checkNoOtherGlobalAdvanceAssignment(
|
||||
DirectAdvanceAssignment newAdvanceAssignment)
|
||||
protected void checkNoOtherGlobalAdvanceAssignment(DirectAdvanceAssignment newAdvanceAssignment)
|
||||
throws DuplicateValueTrueReportGlobalAdvanceException {
|
||||
if (!newAdvanceAssignment.getReportGlobalAdvance()) {
|
||||
|
||||
if ( !newAdvanceAssignment.getReportGlobalAdvance() ) {
|
||||
return;
|
||||
}
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : directAdvanceAssignments) {
|
||||
if (directAdvanceAssignment.getReportGlobalAdvance()) {
|
||||
if ( directAdvanceAssignment.getReportGlobalAdvance() ) {
|
||||
throw new DuplicateValueTrueReportGlobalAdvanceException(
|
||||
_("Cannot spread two progress in the same task"),
|
||||
this, OrderElement.class);
|
||||
|
|
@ -1022,14 +1013,14 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
|
||||
public TaskElement getTaskElement() {
|
||||
TaskSource taskSource = getTaskSource();
|
||||
if (taskSource == null) {
|
||||
if ( taskSource == null ) {
|
||||
return null;
|
||||
}
|
||||
return taskSource.getTask();
|
||||
}
|
||||
|
||||
public Set<TaskElement> getTaskElements() {
|
||||
if (getTaskSource() == null) {
|
||||
if ( getTaskSource() == null ) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return Collections.singleton(getTaskSource().getTask());
|
||||
|
|
@ -1053,8 +1044,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
return result;
|
||||
}
|
||||
|
||||
private void schedulingDataForVersionFromBottomToTop(
|
||||
List<SchedulingDataForVersion> result) {
|
||||
private void schedulingDataForVersionFromBottomToTop(List<SchedulingDataForVersion> result) {
|
||||
for (OrderElement each : getChildren()) {
|
||||
each.schedulingDataForVersionFromBottomToTop(result);
|
||||
}
|
||||
|
|
@ -1065,7 +1055,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
for (OrderElement each : getChildren()) {
|
||||
each.taskSourcesFromBottomToTop(result);
|
||||
}
|
||||
if (getTaskSource() != null) {
|
||||
if ( getTaskSource() != null ) {
|
||||
result.add(getTaskSource());
|
||||
}
|
||||
}
|
||||
|
|
@ -1486,16 +1476,16 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
}
|
||||
|
||||
public void setCodeAutogenerated(Boolean codeAutogenerated) {
|
||||
if (getOrder().equals(this)) {
|
||||
if ( getOrder().equals(this) ) {
|
||||
super.setCodeAutogenerated(codeAutogenerated);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isCodeAutogenerated() {
|
||||
if (getOrder().equals(this)) {
|
||||
if ( getOrder().equals(this) ) {
|
||||
return super.isCodeAutogenerated();
|
||||
}
|
||||
return getOrder() != null ? getOrder().isCodeAutogenerated() : false;
|
||||
return (getOrder() != null) ? getOrder().isCodeAutogenerated() : false;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "a quality form cannot be assigned twice to the same task")
|
||||
|
|
@ -1503,7 +1493,7 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
Set<QualityForm> qualityForms = new HashSet<QualityForm>();
|
||||
for (TaskQualityForm each : taskQualityForms) {
|
||||
QualityForm qualityForm = each.getQualityForm();
|
||||
if (qualityForms.contains(qualityForm)) {
|
||||
if ( qualityForms.contains(qualityForm) ) {
|
||||
return false;
|
||||
}
|
||||
qualityForms.add(qualityForm);
|
||||
|
|
@ -1511,11 +1501,9 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
return true;
|
||||
}
|
||||
|
||||
public void removeDirectAdvancesInList(
|
||||
Set<DirectAdvanceAssignment> directAdvanceAssignments) {
|
||||
public void removeDirectAdvancesInList(Set<DirectAdvanceAssignment> directAdvanceAssignments) {
|
||||
for (DirectAdvanceAssignment each : directAdvanceAssignments) {
|
||||
removeAdvanceAssignment(getAdvanceAssignmentByType(each
|
||||
.getAdvanceType()));
|
||||
removeAdvanceAssignment(getAdvanceAssignmentByType(each.getAdvanceType()));
|
||||
}
|
||||
|
||||
for (OrderElement each : getChildren()) {
|
||||
|
|
@ -1528,31 +1516,29 @@ public abstract class OrderElement extends IntegrationEntity implements ICriteri
|
|||
|
||||
result.addAll(directAdvanceAssignments);
|
||||
|
||||
if (getParent() != null) {
|
||||
result.addAll(getParent()
|
||||
.getDirectAdvanceAssignmentsAndAllInAncest());
|
||||
if ( getParent() != null ) {
|
||||
result.addAll(getParent().getDirectAdvanceAssignmentsAndAllInAncest());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void updateSpreadAdvance() {
|
||||
if (getReportGlobalAdvanceAssignment() == null) {
|
||||
if ( getReportGlobalAdvanceAssignment() == null ) {
|
||||
// Set PERCENTAGE type as spread if any
|
||||
String type = PredefinedAdvancedTypes.PERCENTAGE.getTypeName();
|
||||
for (DirectAdvanceAssignment each : directAdvanceAssignments) {
|
||||
if (each.getAdvanceType() != null
|
||||
&& each.getAdvanceType().getType() != null
|
||||
&& each.getAdvanceType().getType().equals(type)) {
|
||||
if ( each.getAdvanceType() != null &&
|
||||
each.getAdvanceType().getType() != null &&
|
||||
each.getAdvanceType().getType().equals(type) ) {
|
||||
each.setReportGlobalAdvance(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, set first advance assignment
|
||||
if (!directAdvanceAssignments.isEmpty()) {
|
||||
directAdvanceAssignments.iterator().next()
|
||||
.setReportGlobalAdvance(true);
|
||||
if ( !directAdvanceAssignments.isEmpty() ) {
|
||||
directAdvanceAssignments.iterator().next().setReportGlobalAdvance(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ import org.libreplan.business.templates.entities.OrderLineTemplate;
|
|||
|
||||
public class OrderLine extends OrderElement {
|
||||
|
||||
private HoursGroupOrderLineHandler hoursGroupOrderLineHandler = HoursGroupOrderLineHandler
|
||||
.getInstance();
|
||||
private HoursGroupOrderLineHandler hoursGroupOrderLineHandler = HoursGroupOrderLineHandler.getInstance();
|
||||
|
||||
public static OrderLine create() {
|
||||
OrderLine result = new OrderLine();
|
||||
|
|
@ -59,8 +58,7 @@ public class OrderLine extends OrderElement {
|
|||
return orderLine;
|
||||
}
|
||||
|
||||
public static OrderLine createUnvalidatedWithUnfixedPercentage(String code,
|
||||
int hours) {
|
||||
public static OrderLine createUnvalidatedWithUnfixedPercentage(String code, int hours) {
|
||||
OrderLine orderLine = createOrderLineWithUnfixedPercentage(hours);
|
||||
return create(orderLine, code);
|
||||
}
|
||||
|
|
@ -400,4 +398,8 @@ public class OrderLine extends OrderElement {
|
|||
return convertedToContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(OrderLineGroup parent) {
|
||||
super.setParent(parent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,15 +67,12 @@ import org.libreplan.business.trees.ITreeParentNode;
|
|||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class OrderLineGroup extends OrderElement implements
|
||||
ITreeParentNode<OrderElement> {
|
||||
public class OrderLineGroup extends OrderElement implements ITreeParentNode<OrderElement> {
|
||||
|
||||
private final class ChildrenManipulator extends
|
||||
TreeNodeOnListWithSchedulingState<OrderElement> {
|
||||
private final class ChildrenManipulator extends TreeNodeOnListWithSchedulingState<OrderElement> {
|
||||
|
||||
|
||||
private ChildrenManipulator(OrderLineGroup parent,
|
||||
List<OrderElement> children) {
|
||||
private ChildrenManipulator(List<OrderElement> children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
|
|
@ -91,9 +88,8 @@ public class OrderLineGroup extends OrderElement implements
|
|||
|
||||
@Override
|
||||
protected SchedulingState getSchedulingStateFrom(OrderElement node) {
|
||||
if (!node.isSchedulingDataInitialized()) {
|
||||
node.useSchedulingDataFor(getCurrentSchedulingData()
|
||||
.getOriginOrderVersion());
|
||||
if ( !node.isSchedulingDataInitialized() ) {
|
||||
node.useSchedulingDataFor(getCurrentSchedulingData().getOriginOrderVersion());
|
||||
}
|
||||
return node.getSchedulingState();
|
||||
}
|
||||
|
|
@ -114,7 +110,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
removeChildTask(removedChild);
|
||||
}
|
||||
updateCriterionRequirements();
|
||||
if (!removedChild.isNewObject()) {
|
||||
if ( !removedChild.isNewObject() ) {
|
||||
getOrder().markAsNeededToRecalculateSumChargedEfforts();
|
||||
getOrder().markAsNeededToRecalculateSumExpenses();
|
||||
}
|
||||
|
|
@ -123,8 +119,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
private void removeChildTask(OrderElement removedChild) {
|
||||
TaskSource taskSource = removedChild.getTaskSource();
|
||||
TaskElement childTask = taskSource.getTask();
|
||||
TaskGroup group = (TaskGroup) getThis().getTaskSource()
|
||||
.getTask();
|
||||
TaskGroup group = (TaskGroup) getThis().getTaskSource().getTask();
|
||||
group.remove(childTask);
|
||||
childTask.detachDependencies();
|
||||
}
|
||||
|
|
@ -184,8 +179,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
|
||||
public void addChildrenAdvanceOrderLineGroup() {
|
||||
boolean spread = (getReportGlobalAdvanceAssignment() == null);
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment = IndirectAdvanceAssignment
|
||||
.create(spread);
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment = IndirectAdvanceAssignment.create(spread);
|
||||
AdvanceType advanceType = PredefinedAdvancedTypes.CHILDREN.getType();
|
||||
indirectAdvanceAssignment.setAdvanceType(advanceType);
|
||||
indirectAdvanceAssignment.setOrderElement(this);
|
||||
|
|
@ -194,8 +188,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
|
||||
public void removeChildrenAdvanceOrderLineGroup() {
|
||||
for (IndirectAdvanceAssignment advance : getIndirectAdvanceAssignments()) {
|
||||
if (advance.getAdvanceType().getUnitName().equals(
|
||||
PredefinedAdvancedTypes.CHILDREN.getTypeName())) {
|
||||
if ( advance.getAdvanceType().getUnitName().equals(PredefinedAdvancedTypes.CHILDREN.getTypeName()) ) {
|
||||
indirectAdvanceAssignments.remove(advance);
|
||||
updateSpreadAdvance();
|
||||
}
|
||||
|
|
@ -204,22 +197,21 @@ public class OrderLineGroup extends OrderElement implements
|
|||
|
||||
@Override
|
||||
protected void updateSpreadAdvance() {
|
||||
if (getReportGlobalAdvanceAssignment() == null) {
|
||||
if ( getReportGlobalAdvanceAssignment() == null ) {
|
||||
// Set CHILDREN type as spread if any
|
||||
String type = PredefinedAdvancedTypes.CHILDREN.getTypeName();
|
||||
for (IndirectAdvanceAssignment each : indirectAdvanceAssignments) {
|
||||
if (each.getAdvanceType() != null
|
||||
&& each.getAdvanceType().getType() != null
|
||||
&& each.getAdvanceType().getType().equals(type)) {
|
||||
if ( each.getAdvanceType() != null &&
|
||||
each.getAdvanceType().getType() != null &&
|
||||
each.getAdvanceType().getType().equals(type) ) {
|
||||
each.setReportGlobalAdvance(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, set first indirect advance assignment
|
||||
if (!indirectAdvanceAssignments.isEmpty()) {
|
||||
indirectAdvanceAssignments.iterator().next()
|
||||
.setReportGlobalAdvance(true);
|
||||
if ( !indirectAdvanceAssignments.isEmpty() ) {
|
||||
indirectAdvanceAssignments.iterator().next().setReportGlobalAdvance(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -289,46 +281,38 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
|
||||
private void addIndirectAdvanceAssignments(OrderElement orderElement) {
|
||||
orderElement
|
||||
.removeDirectAdvancesInList(getDirectAdvanceAssignmentsAndAllInAncest());
|
||||
orderElement.removeDirectAdvancesInList(getDirectAdvanceAssignmentsAndAllInAncest());
|
||||
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : orderElement.directAdvanceAssignments) {
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment = IndirectAdvanceAssignment
|
||||
.create();
|
||||
indirectAdvanceAssignment.setAdvanceType(directAdvanceAssignment
|
||||
.getAdvanceType());
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment = IndirectAdvanceAssignment.create();
|
||||
indirectAdvanceAssignment.setAdvanceType(directAdvanceAssignment.getAdvanceType());
|
||||
indirectAdvanceAssignment.setOrderElement(this);
|
||||
this.addIndirectAdvanceAssignment(indirectAdvanceAssignment);
|
||||
}
|
||||
|
||||
if (orderElement instanceof OrderLineGroup) {
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : ((OrderLineGroup) orderElement)
|
||||
.getIndirectAdvanceAssignments()) {
|
||||
if ( orderElement instanceof OrderLineGroup ) {
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : orderElement.getIndirectAdvanceAssignments()) {
|
||||
this.addIndirectAdvanceAssignment(indirectAdvanceAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
if (!indirectAdvanceAssignments.isEmpty()) {
|
||||
if ( !indirectAdvanceAssignments.isEmpty() ) {
|
||||
addChildrenAdvanceOrderLineGroup();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeIndirectAdvanceAssignments(OrderElement orderElement) {
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : orderElement.directAdvanceAssignments) {
|
||||
this.removeIndirectAdvanceAssignment(directAdvanceAssignment
|
||||
.getAdvanceType());
|
||||
this.removeIndirectAdvanceAssignment(directAdvanceAssignment.getAdvanceType());
|
||||
}
|
||||
|
||||
if (orderElement instanceof OrderLineGroup) {
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : ((OrderLineGroup) orderElement)
|
||||
.getIndirectAdvanceAssignments()) {
|
||||
this.removeIndirectAdvanceAssignment(indirectAdvanceAssignment
|
||||
.getAdvanceType());
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : orderElement.getIndirectAdvanceAssignments()) {
|
||||
this.removeIndirectAdvanceAssignment(indirectAdvanceAssignment.getAdvanceType());
|
||||
}
|
||||
}
|
||||
|
||||
if (children.isEmpty() && (indirectAdvanceAssignments.size() == 1)
|
||||
&& existChildrenAdvance()) {
|
||||
if ( children.isEmpty() && (indirectAdvanceAssignments.size() == 1) && existChildrenAdvance() ) {
|
||||
removeChildrenAdvanceOrderLineGroup();
|
||||
}
|
||||
}
|
||||
|
|
@ -339,7 +323,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
|
||||
private ChildrenManipulator getManipulator() {
|
||||
return new ChildrenManipulator(this, children);
|
||||
return new ChildrenManipulator(children);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -369,8 +353,8 @@ public class OrderLineGroup extends OrderElement implements
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Set<DirectAdvanceAssignment> copyDirectAdvanceAssignments(
|
||||
OrderElement origin, OrderElement destination) {
|
||||
private static Set<DirectAdvanceAssignment> copyDirectAdvanceAssignments(OrderElement origin,
|
||||
OrderElement destination) {
|
||||
Set<DirectAdvanceAssignment> result = new HashSet<DirectAdvanceAssignment>();
|
||||
for (DirectAdvanceAssignment each : origin.directAdvanceAssignments) {
|
||||
result.add(DirectAdvanceAssignment.copy(each, destination));
|
||||
|
|
@ -378,8 +362,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Set<MaterialAssignment> copyMaterialAssignments(
|
||||
OrderElement origin, OrderElement destination) {
|
||||
private static Set<MaterialAssignment> copyMaterialAssignments(OrderElement origin, OrderElement destination) {
|
||||
Set<MaterialAssignment> result = new HashSet<MaterialAssignment>();
|
||||
for (MaterialAssignment each : origin.materialAssignments) {
|
||||
result.add(MaterialAssignment.copy(each, destination));
|
||||
|
|
@ -387,8 +370,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Set<Label> copyLabels(
|
||||
OrderElement origin, OrderElement destination) {
|
||||
private static Set<Label> copyLabels(OrderElement origin, OrderElement destination) {
|
||||
Set<Label> result = new HashSet<Label>();
|
||||
for (Label each : origin.labels) {
|
||||
destination.addLabel(each);
|
||||
|
|
@ -397,8 +379,7 @@ public class OrderLineGroup extends OrderElement implements
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Set<TaskQualityForm> copyTaskQualityForms(
|
||||
OrderElement origin, OrderElement destination) {
|
||||
private static Set<TaskQualityForm> copyTaskQualityForms(OrderElement origin, OrderElement destination) {
|
||||
Set<TaskQualityForm> result = new HashSet<TaskQualityForm>();
|
||||
for (TaskQualityForm each : origin.taskQualityForms) {
|
||||
result.add(TaskQualityForm.copy(each, destination));
|
||||
|
|
@ -451,8 +432,8 @@ public class OrderLineGroup extends OrderElement implements
|
|||
@Override
|
||||
public BigDecimal getAdvancePercentage(LocalDate date) {
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : directAdvanceAssignments) {
|
||||
if (directAdvanceAssignment.getReportGlobalAdvance()) {
|
||||
if (date == null) {
|
||||
if ( directAdvanceAssignment.getReportGlobalAdvance() ) {
|
||||
if ( date == null ) {
|
||||
return directAdvanceAssignment.getAdvancePercentage();
|
||||
}
|
||||
return directAdvanceAssignment.getAdvancePercentage(date);
|
||||
|
|
@ -460,16 +441,20 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {
|
||||
if (indirectAdvanceAssignment.getReportGlobalAdvance()) {
|
||||
if (indirectAdvanceAssignment.getAdvanceType().getUnitName()
|
||||
.equals(PredefinedAdvancedTypes.CHILDREN.getTypeName())) {
|
||||
if (date == null) {
|
||||
if ( indirectAdvanceAssignment.getReportGlobalAdvance() ) {
|
||||
|
||||
if ( indirectAdvanceAssignment.getAdvanceType().getUnitName().equals(
|
||||
PredefinedAdvancedTypes.CHILDREN.getTypeName()) ) {
|
||||
|
||||
if ( date == null ) {
|
||||
return getAdvancePercentageChildren();
|
||||
}
|
||||
return getAdvancePercentageChildren(date);
|
||||
} else {
|
||||
DirectAdvanceAssignment directAdvanceAssignment = calculateFakeDirectAdvanceAssignment(indirectAdvanceAssignment);
|
||||
if (date == null) {
|
||||
DirectAdvanceAssignment directAdvanceAssignment =
|
||||
calculateFakeDirectAdvanceAssignment(indirectAdvanceAssignment);
|
||||
|
||||
if ( date == null ) {
|
||||
return directAdvanceAssignment.getAdvancePercentage();
|
||||
}
|
||||
return directAdvanceAssignment.getAdvancePercentage(date);
|
||||
|
|
@ -489,20 +474,18 @@ public class OrderLineGroup extends OrderElement implements
|
|||
Integer hours = getWorkHours();
|
||||
BigDecimal result = new BigDecimal(0);
|
||||
|
||||
if (hours > 0) {
|
||||
if ( hours > 0 ) {
|
||||
for (OrderElement orderElement : children) {
|
||||
BigDecimal childPercentage;
|
||||
if (date == null) {
|
||||
if ( date == null ) {
|
||||
childPercentage = orderElement.getAdvancePercentage();
|
||||
} else {
|
||||
childPercentage = orderElement.getAdvancePercentage(date);
|
||||
}
|
||||
Integer childHours = orderElement.getWorkHours();
|
||||
result = result.add(childPercentage.multiply(new BigDecimal(
|
||||
childHours)));
|
||||
result = result.add(childPercentage.multiply(new BigDecimal(childHours)));
|
||||
}
|
||||
result = result.divide(new BigDecimal(hours).setScale(2), 4,
|
||||
RoundingMode.DOWN);
|
||||
result = result.divide(new BigDecimal(hours).setScale(2), 4, RoundingMode.DOWN);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -512,52 +495,47 @@ public class OrderLineGroup extends OrderElement implements
|
|||
@Override
|
||||
public DirectAdvanceAssignment calculateFakeDirectAdvanceAssignment(
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment) {
|
||||
if (indirectAdvanceAssignment.getAdvanceType().getUnitName().equals(
|
||||
PredefinedAdvancedTypes.CHILDREN.getTypeName())) {
|
||||
|
||||
if ( indirectAdvanceAssignment.getAdvanceType().getUnitName().equals(
|
||||
PredefinedAdvancedTypes.CHILDREN.getTypeName()) ) {
|
||||
|
||||
return calculateFakeDirectAdvanceAssignmentChildren(indirectAdvanceAssignment);
|
||||
} else {
|
||||
Set<DirectAdvanceAssignment> directAdvanceAssignments = getAllDirectAdvanceAssignments(indirectAdvanceAssignment
|
||||
.getAdvanceType());
|
||||
return mergeAdvanceAssignments(new ArrayList<DirectAdvanceAssignment>(
|
||||
directAdvanceAssignments));
|
||||
Set<DirectAdvanceAssignment> directAdvanceAssignments =
|
||||
getAllDirectAdvanceAssignments(indirectAdvanceAssignment.getAdvanceType());
|
||||
|
||||
return mergeAdvanceAssignments(new ArrayList<DirectAdvanceAssignment>(directAdvanceAssignments));
|
||||
}
|
||||
}
|
||||
|
||||
private DirectAdvanceAssignment calculateFakeDirectAdvanceAssignmentChildren(
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment) {
|
||||
DirectAdvanceAssignment newDirectAdvanceAssignment = DirectAdvanceAssignment
|
||||
.create();
|
||||
|
||||
DirectAdvanceAssignment newDirectAdvanceAssignment = DirectAdvanceAssignment.create();
|
||||
newDirectAdvanceAssignment.setFake(true);
|
||||
newDirectAdvanceAssignment.setMaxValue(new BigDecimal(100));
|
||||
newDirectAdvanceAssignment.setAdvanceType(indirectAdvanceAssignment
|
||||
.getAdvanceType());
|
||||
newDirectAdvanceAssignment.setAdvanceType(indirectAdvanceAssignment.getAdvanceType());
|
||||
newDirectAdvanceAssignment.setOrderElement(this);
|
||||
|
||||
Set<DirectAdvanceAssignment> directAdvanceAssignments = new HashSet<DirectAdvanceAssignment>();
|
||||
for (OrderElement orderElement : children) {
|
||||
directAdvanceAssignments.addAll(orderElement
|
||||
.getAllDirectAdvanceAssignmentsReportGlobal());
|
||||
directAdvanceAssignments.addAll(orderElement.getAllDirectAdvanceAssignmentsReportGlobal());
|
||||
}
|
||||
|
||||
List<AdvanceMeasurement> advanceMeasurements = new ArrayList<AdvanceMeasurement>();
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : directAdvanceAssignments) {
|
||||
advanceMeasurements.addAll(directAdvanceAssignment
|
||||
.getAdvanceMeasurements());
|
||||
advanceMeasurements.addAll(directAdvanceAssignment.getAdvanceMeasurements());
|
||||
}
|
||||
|
||||
List<LocalDate> measurementDates = getMeasurementDates(advanceMeasurements);
|
||||
SortedSet<AdvanceMeasurement> newAdvanceMeasurements = new TreeSet<AdvanceMeasurement>(
|
||||
new AdvanceMeasurementComparator());
|
||||
SortedSet<AdvanceMeasurement> newAdvanceMeasurements = new TreeSet<AdvanceMeasurement>(new AdvanceMeasurementComparator());
|
||||
for (LocalDate localDate : measurementDates) {
|
||||
BigDecimal value = getAdvancePercentageChildren(localDate)
|
||||
.multiply(new BigDecimal(100));
|
||||
AdvanceMeasurement advanceMeasurement = AdvanceMeasurement.create(
|
||||
localDate, value);
|
||||
BigDecimal value = getAdvancePercentageChildren(localDate).multiply(new BigDecimal(100));
|
||||
AdvanceMeasurement advanceMeasurement = AdvanceMeasurement.create(localDate, value);
|
||||
advanceMeasurement.setAdvanceAssignment(newDirectAdvanceAssignment);
|
||||
newAdvanceMeasurements.add(advanceMeasurement);
|
||||
}
|
||||
newDirectAdvanceAssignment
|
||||
.setAdvanceMeasurements(newAdvanceMeasurements);
|
||||
newDirectAdvanceAssignment.setAdvanceMeasurements(newAdvanceMeasurements);
|
||||
|
||||
return newDirectAdvanceAssignment;
|
||||
}
|
||||
|
|
@ -847,49 +825,42 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(
|
||||
AdvanceType advanceType) {
|
||||
public Set<DirectAdvanceAssignment> getAllDirectAdvanceAssignments(AdvanceType advanceType) {
|
||||
Set<DirectAdvanceAssignment> result = new HashSet<DirectAdvanceAssignment>();
|
||||
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : directAdvanceAssignments) {
|
||||
if (directAdvanceAssignment.getAdvanceType().getUnitName().equals(advanceType.getUnitName())) {
|
||||
if ( directAdvanceAssignment.getAdvanceType().getUnitName().equals(advanceType.getUnitName()) ) {
|
||||
result.add(directAdvanceAssignment);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
for (OrderElement orderElement : children) {
|
||||
result
|
||||
.addAll(orderElement
|
||||
.getAllDirectAdvanceAssignments(advanceType));
|
||||
result.addAll(orderElement.getAllDirectAdvanceAssignments(advanceType));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IndirectAdvanceAssignment> getAllIndirectAdvanceAssignments(
|
||||
AdvanceType advanceType) {
|
||||
public Set<IndirectAdvanceAssignment> getAllIndirectAdvanceAssignments(AdvanceType advanceType) {
|
||||
Set<IndirectAdvanceAssignment> result = new HashSet<IndirectAdvanceAssignment>();
|
||||
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment = getIndirectAdvanceAssignment(advanceType);
|
||||
if(indirectAdvanceAssignment != null){
|
||||
if( indirectAdvanceAssignment != null ){
|
||||
result.add(indirectAdvanceAssignment);
|
||||
}
|
||||
|
||||
for (OrderElement orderElement : children) {
|
||||
result.addAll(orderElement
|
||||
.getAllIndirectAdvanceAssignments(advanceType));
|
||||
result.addAll(orderElement.getAllIndirectAdvanceAssignments(advanceType));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IndirectAdvanceAssignment getIndirectAdvanceAssignment(
|
||||
AdvanceType advanceType) {
|
||||
public IndirectAdvanceAssignment getIndirectAdvanceAssignment(AdvanceType advanceType) {
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {
|
||||
if (indirectAdvanceAssignment.getAdvanceType().getUnitName()
|
||||
.equals(advanceType.getUnitName())) {
|
||||
if ( indirectAdvanceAssignment.getAdvanceType().getUnitName().equals(advanceType.getUnitName()) ) {
|
||||
return indirectAdvanceAssignment;
|
||||
}
|
||||
}
|
||||
|
|
@ -901,14 +872,13 @@ public class OrderLineGroup extends OrderElement implements
|
|||
Set<DirectAdvanceAssignment> result = new HashSet<DirectAdvanceAssignment>();
|
||||
|
||||
for (DirectAdvanceAssignment directAdvanceAssignment : directAdvanceAssignments) {
|
||||
if (directAdvanceAssignment.getReportGlobalAdvance()) {
|
||||
if ( directAdvanceAssignment.getReportGlobalAdvance() ) {
|
||||
result.add(directAdvanceAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
for (OrderElement orderElement : children) {
|
||||
result.addAll(orderElement
|
||||
.getAllDirectAdvanceAssignmentsReportGlobal());
|
||||
result.addAll(orderElement.getAllDirectAdvanceAssignmentsReportGlobal());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -932,43 +902,38 @@ public class OrderLineGroup extends OrderElement implements
|
|||
return Collections.unmodifiableSet(indirectAdvanceAssignments);
|
||||
}
|
||||
|
||||
public void addIndirectAdvanceAssignment(
|
||||
IndirectAdvanceAssignment indirectAdvanceAssignment) {
|
||||
if ((!existsIndirectAdvanceAssignmentWithTheSameType(indirectAdvanceAssignment
|
||||
.getAdvanceType()))
|
||||
&& (!existsDirectAdvanceAssignmentWithTheSameType(indirectAdvanceAssignment
|
||||
.getAdvanceType()))) {
|
||||
public void addIndirectAdvanceAssignment(IndirectAdvanceAssignment indirectAdvanceAssignment) {
|
||||
|
||||
if ( (!existsIndirectAdvanceAssignmentWithTheSameType(indirectAdvanceAssignment.getAdvanceType())) &&
|
||||
(!existsDirectAdvanceAssignmentWithTheSameType(indirectAdvanceAssignment.getAdvanceType())) ) {
|
||||
|
||||
indirectAdvanceAssignments.add(indirectAdvanceAssignment);
|
||||
}
|
||||
if (parent != null) {
|
||||
parent.addIndirectAdvanceAssignment(indirectAdvanceAssignment
|
||||
.createIndirectAdvanceFor(parent));
|
||||
if ( parent != null ) {
|
||||
parent.addIndirectAdvanceAssignment(indirectAdvanceAssignment.createIndirectAdvanceFor(parent));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeIndirectAdvanceAssignment(AdvanceType advanceType) {
|
||||
DirectAdvanceAssignment tempAdavanceAssignmet = DirectAdvanceAssignment
|
||||
.create();
|
||||
DirectAdvanceAssignment tempAdavanceAssignmet = DirectAdvanceAssignment.create();
|
||||
tempAdavanceAssignmet.setAdvanceType(advanceType);
|
||||
|
||||
try {
|
||||
checkChildrenNoOtherAssignmentWithSameAdvanceType(this,
|
||||
tempAdavanceAssignmet);
|
||||
checkChildrenNoOtherAssignmentWithSameAdvanceType(this, tempAdavanceAssignmet);
|
||||
|
||||
String unitName = advanceType.getUnitName();
|
||||
IndirectAdvanceAssignment toRemove = null;
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {
|
||||
if (unitName.equals(indirectAdvanceAssignment.getAdvanceType()
|
||||
.getUnitName())) {
|
||||
if ( unitName.equals(indirectAdvanceAssignment.getAdvanceType().getUnitName()) ) {
|
||||
toRemove = indirectAdvanceAssignment;
|
||||
}
|
||||
}
|
||||
if (toRemove != null) {
|
||||
if ( toRemove != null ) {
|
||||
indirectAdvanceAssignments.remove(toRemove);
|
||||
updateSpreadAdvance();
|
||||
}
|
||||
|
||||
if (parent != null) {
|
||||
if ( parent != null ) {
|
||||
parent.removeIndirectAdvanceAssignment(advanceType);
|
||||
}
|
||||
} catch (DuplicateAdvanceAssignmentForOrderElementException e) {
|
||||
|
|
@ -978,12 +943,10 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
}
|
||||
|
||||
public boolean existsIndirectAdvanceAssignmentWithTheSameType(
|
||||
AdvanceType type) {
|
||||
public boolean existsIndirectAdvanceAssignmentWithTheSameType(AdvanceType type) {
|
||||
String unitName = type.getUnitName();
|
||||
for (IndirectAdvanceAssignment indirectAdvanceAssignment : indirectAdvanceAssignments) {
|
||||
if (unitName.equals(indirectAdvanceAssignment.getAdvanceType()
|
||||
.getUnitName())) {
|
||||
if ( unitName.equals(indirectAdvanceAssignment.getAdvanceType().getUnitName()) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -991,17 +954,17 @@ public class OrderLineGroup extends OrderElement implements
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void checkNoOtherGlobalAdvanceAssignment(
|
||||
DirectAdvanceAssignment newAdvanceAssignment)
|
||||
protected void checkNoOtherGlobalAdvanceAssignment(DirectAdvanceAssignment newAdvanceAssignment)
|
||||
throws DuplicateValueTrueReportGlobalAdvanceException {
|
||||
if (!newAdvanceAssignment.getReportGlobalAdvance()) {
|
||||
|
||||
if ( !newAdvanceAssignment.getReportGlobalAdvance() ) {
|
||||
return;
|
||||
}
|
||||
Set<AdvanceAssignment> advanceAssignments = new HashSet<AdvanceAssignment>();
|
||||
advanceAssignments.addAll(directAdvanceAssignments);
|
||||
advanceAssignments.addAll(indirectAdvanceAssignments);
|
||||
for (AdvanceAssignment advanceAssignment : advanceAssignments) {
|
||||
if (advanceAssignment.getReportGlobalAdvance()) {
|
||||
if ( advanceAssignment.getReportGlobalAdvance() ) {
|
||||
throw new DuplicateValueTrueReportGlobalAdvanceException(
|
||||
_("Cannot spread two progress in the same task"),
|
||||
this, OrderElement.class);
|
||||
|
|
|
|||
|
|
@ -39,10 +39,8 @@ public class SchedulingDataForVersion extends BaseEntity {
|
|||
|
||||
public static class Data {
|
||||
|
||||
private static Data from(SchedulingDataForVersion version,
|
||||
OrderVersion orderVersion) {
|
||||
return new Data(orderVersion, version, version
|
||||
.getTaskSource(), version.getSchedulingStateType());
|
||||
private static Data from(SchedulingDataForVersion version, OrderVersion orderVersion) {
|
||||
return new Data(orderVersion, version, version.getTaskSource(), version.getSchedulingStateType());
|
||||
}
|
||||
|
||||
private SchedulingDataForVersion originVersion;
|
||||
|
|
@ -58,9 +56,10 @@ public class SchedulingDataForVersion extends BaseEntity {
|
|||
private final Type initialSchedulingStateType;
|
||||
|
||||
private Data(OrderVersion orderVersion,
|
||||
SchedulingDataForVersion version,
|
||||
TaskSource taskSource,
|
||||
Type schedulingStateType) {
|
||||
SchedulingDataForVersion version,
|
||||
TaskSource taskSource,
|
||||
Type schedulingStateType) {
|
||||
|
||||
Validate.notNull(schedulingStateType);
|
||||
this.originOrderVersion = orderVersion;
|
||||
this.originVersion = version;
|
||||
|
|
@ -77,8 +76,7 @@ public class SchedulingDataForVersion extends BaseEntity {
|
|||
return schedulingStateType;
|
||||
}
|
||||
|
||||
private void setSchedulingStateType(
|
||||
SchedulingState.Type schedulingStateType) {
|
||||
private void setSchedulingStateType(SchedulingState.Type schedulingStateType) {
|
||||
this.schedulingStateType = schedulingStateType;
|
||||
hasPendingChanges = true;
|
||||
}
|
||||
|
|
@ -109,14 +107,12 @@ public class SchedulingDataForVersion extends BaseEntity {
|
|||
}
|
||||
|
||||
public void requestedCreationOf(TaskSource taskSource) {
|
||||
Validate.isTrue(this.getTaskSource() == null,
|
||||
"there must be no task source");
|
||||
Validate.isTrue(this.getTaskSource() == null, "there must be no task source");
|
||||
this.setTaskSource(taskSource);
|
||||
}
|
||||
|
||||
public void replaceCurrentTaskSourceWith(TaskSource newTaskSource) {
|
||||
Validate.isTrue(this.getTaskSource() != null,
|
||||
"there must be a task source to replace");
|
||||
Validate.isTrue(this.getTaskSource() != null, "there must be a task source to replace");
|
||||
this.setTaskSource(newTaskSource);
|
||||
}
|
||||
|
||||
|
|
@ -162,8 +158,7 @@ public class SchedulingDataForVersion extends BaseEntity {
|
|||
}
|
||||
|
||||
private static Type defaultTypeFor(OrderElement orderElement) {
|
||||
return orderElement.isLeaf() ? Type.SCHEDULING_POINT
|
||||
: Type.NO_SCHEDULED;
|
||||
return orderElement.isLeaf() ? Type.SCHEDULING_POINT : Type.NO_SCHEDULED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
@ -193,7 +188,8 @@ public class SchedulingDataForVersion extends BaseEntity {
|
|||
|
||||
void removeSpuriousDayAssignments(Scenario scenario) {
|
||||
TaskSource taskSource = getTaskSource();
|
||||
if (taskSource != null) {
|
||||
|
||||
if ( taskSource != null ) {
|
||||
TaskElement task = taskSource.getTask();
|
||||
task.removeDayAssignmentsFor(scenario);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public abstract class TreeNodeOnListWithSchedulingState<T extends ITreeNode<T>>
|
|||
|
||||
protected void removeFromPreviousSchedulingState(T node) {
|
||||
SchedulingState schedulingState = getSchedulingStateFrom(node);
|
||||
if (!schedulingState.isRoot()) {
|
||||
if ( !schedulingState.isRoot() ) {
|
||||
schedulingState.getParent().removeChild(schedulingState);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ public class AssignedEffortForResource {
|
|||
* @return A {@link IAssignedEffortForResource} that calculates the load
|
||||
* associated for all allocations but the provided ones.
|
||||
*/
|
||||
public static IAssignedEffortForResource effortDiscounting(
|
||||
Collection<? extends BaseEntity> allocations) {
|
||||
public static IAssignedEffortForResource effortDiscounting(Collection<? extends BaseEntity> allocations) {
|
||||
return new AssignedEffortDiscounting(allocations);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,10 +51,11 @@ public class CompanyEarnedValueCalculator extends EarnedValueCalculator implemen
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkScheduled(AvailabilityTimeLine.Interval interval) {
|
||||
Map<TaskElement, SortedMap<LocalDate, BigDecimal>> estimatedCostPerTask = databaseSnapshots
|
||||
.snapshotEstimatedCostPerTask();
|
||||
Collection<TaskElement> list = filterTasksByDate(
|
||||
estimatedCostPerTask.keySet(), interval);
|
||||
|
||||
Map<TaskElement, SortedMap<LocalDate, BigDecimal>> estimatedCostPerTask =
|
||||
databaseSnapshots.snapshotEstimatedCostPerTask();
|
||||
|
||||
Collection<TaskElement> list = filterTasksByDate(estimatedCostPerTask.keySet(), interval);
|
||||
SortedMap<LocalDate, BigDecimal> estimatedCost = new TreeMap<LocalDate, BigDecimal>();
|
||||
|
||||
for (TaskElement each : list) {
|
||||
|
|
@ -63,25 +64,21 @@ public class CompanyEarnedValueCalculator extends EarnedValueCalculator implemen
|
|||
return accumulateResult(estimatedCost);
|
||||
}
|
||||
|
||||
private List<TaskElement> filterTasksByDate(
|
||||
Collection<TaskElement> tasks,
|
||||
AvailabilityTimeLine.Interval interval) {
|
||||
private List<TaskElement> filterTasksByDate(Collection<TaskElement> tasks, AvailabilityTimeLine.Interval interval) {
|
||||
List<TaskElement> result = new ArrayList<TaskElement>();
|
||||
for(TaskElement task : tasks) {
|
||||
if (interval.includes(task.getStartAsLocalDate())
|
||||
|| interval.includes(task.getEndAsLocalDate())) {
|
||||
if ( interval.includes(task.getStartAsLocalDate()) || interval.includes(task.getEndAsLocalDate()) ) {
|
||||
result.add(task);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<WorkReportLine> filterWorkReportLinesByDate(
|
||||
Collection<WorkReportLine> lines,
|
||||
AvailabilityTimeLine.Interval interval) {
|
||||
private List<WorkReportLine> filterWorkReportLinesByDate(Collection<WorkReportLine> lines,
|
||||
AvailabilityTimeLine.Interval interval) {
|
||||
List<WorkReportLine> result = new ArrayList<WorkReportLine>();
|
||||
for(WorkReportLine line: lines) {
|
||||
if (interval.includes(line.getLocalDate())) {
|
||||
if ( interval.includes(line.getLocalDate()) ) {
|
||||
result.add(line);
|
||||
}
|
||||
}
|
||||
|
|
@ -89,13 +86,13 @@ public class CompanyEarnedValueCalculator extends EarnedValueCalculator implemen
|
|||
}
|
||||
|
||||
private void addCost(SortedMap<LocalDate, BigDecimal> currentCost,
|
||||
SortedMap<LocalDate, BigDecimal> additionalCost) {
|
||||
SortedMap<LocalDate, BigDecimal> additionalCost) {
|
||||
|
||||
for (LocalDate day : additionalCost.keySet()) {
|
||||
if (!currentCost.containsKey(day)) {
|
||||
if ( !currentCost.containsKey(day) ) {
|
||||
currentCost.put(day, BigDecimal.ZERO);
|
||||
}
|
||||
currentCost.put(day, currentCost.get(day).add(
|
||||
additionalCost.get(day)));
|
||||
currentCost.put(day, currentCost.get(day).add(additionalCost.get(day)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,10 +73,11 @@ public class GenericResourceAllocation extends
|
|||
|
||||
public static Map<Set<Criterion>, List<GenericResourceAllocation>> byCriterions(
|
||||
Collection<GenericResourceAllocation> genericAllocations) {
|
||||
|
||||
Map<Set<Criterion>, List<GenericResourceAllocation>> result = new HashMap<Set<Criterion>, List<GenericResourceAllocation>>();
|
||||
for (GenericResourceAllocation genericResourceAllocation : genericAllocations) {
|
||||
Set<Criterion> criterions = genericResourceAllocation.getCriterions();
|
||||
if(! result.containsKey(criterions)){
|
||||
if( !result.containsKey(criterions) ){
|
||||
result.put(criterions, new ArrayList<GenericResourceAllocation>());
|
||||
}
|
||||
result.get(criterions).add(genericResourceAllocation);
|
||||
|
|
@ -128,8 +129,8 @@ public class GenericResourceAllocation extends
|
|||
return first.getType().getResource();
|
||||
}
|
||||
|
||||
public static GenericResourceAllocation create(Task task,
|
||||
ResourceEnum resourceType, Collection<? extends Criterion> criterions) {
|
||||
public static GenericResourceAllocation create(Task task, ResourceEnum resourceType,
|
||||
Collection<? extends Criterion> criterions) {
|
||||
Validate.notNull(resourceType);
|
||||
GenericResourceAllocation result = new GenericResourceAllocation(task);
|
||||
result.criterions = new HashSet<Criterion>(criterions);
|
||||
|
|
@ -208,8 +209,7 @@ public class GenericResourceAllocation extends
|
|||
|
||||
public GenericAllocation(List<Resource> resources) {
|
||||
this.resources = resources;
|
||||
hoursDistributor = new EffortDistributor(resources,
|
||||
getAssignedEffortForResource(),
|
||||
hoursDistributor = new EffortDistributor(resources, getAssignedEffortForResource(),
|
||||
new ResourcesSatisfyingCriterionsSelector());
|
||||
}
|
||||
|
||||
|
|
@ -227,8 +227,7 @@ public class GenericResourceAllocation extends
|
|||
|
||||
@Override
|
||||
protected AvailabilityTimeLine getResourcesAvailability() {
|
||||
return AvailabilityCalculator.buildSumOfAvailabilitiesFor(
|
||||
getCriterions(), resources);
|
||||
return AvailabilityCalculator.buildSumOfAvailabilitiesFor(getCriterions(), resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,10 +24,14 @@ package org.libreplan.business.planner.entities;
|
|||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.sql.Time;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.SortedMap;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.advance.entities.AdvanceMeasurement;
|
||||
|
|
@ -44,6 +48,7 @@ import org.springframework.stereotype.Component;
|
|||
* Cost calulator in terms of hours.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
|
|
@ -58,16 +63,17 @@ public class HoursCostCalculator implements ICostCalculator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<LocalDate, BigDecimal> getAdvanceCost(Task task,
|
||||
LocalDate filterStartDate, LocalDate filterEndDate) {
|
||||
DirectAdvanceAssignment advanceAssignment = (task.getOrderElement() != null) ? task
|
||||
.getOrderElement().getReportGlobalAdvanceAssignment() : null;
|
||||
public SortedMap<LocalDate, BigDecimal> getAdvanceCost(Task task, LocalDate filterStartDate,
|
||||
LocalDate filterEndDate) {
|
||||
DirectAdvanceAssignment advanceAssignment =
|
||||
(task.getOrderElement() != null) ? task.getOrderElement().getReportGlobalAdvanceAssignment() : null;
|
||||
|
||||
if (advanceAssignment == null) {
|
||||
if ( advanceAssignment == null ) {
|
||||
return new TreeMap<LocalDate, BigDecimal>();
|
||||
}
|
||||
|
||||
return calculateHoursPerDay(task.getHoursSpecifiedAtOrder(),
|
||||
return calculateHoursPerDay(
|
||||
task.getHoursSpecifiedAtOrder(),
|
||||
advanceAssignment.getAdvanceMeasurements(),
|
||||
filterStartDate, filterEndDate);
|
||||
}
|
||||
|
|
@ -76,16 +82,17 @@ public class HoursCostCalculator implements ICostCalculator {
|
|||
Integer totalHours,
|
||||
SortedSet<AdvanceMeasurement> advanceMeasurements,
|
||||
LocalDate filterStartDate, LocalDate filterEndDate) {
|
||||
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
|
||||
for (AdvanceMeasurement advanceMeasurement : advanceMeasurements) {
|
||||
LocalDate day = advanceMeasurement.getDate();
|
||||
if(((filterStartDate == null) || day.compareTo(filterStartDate) >= 0) &&
|
||||
((filterEndDate == null) || day.compareTo(filterEndDate) <= 0)) {
|
||||
if( ((filterStartDate == null) || day.compareTo(filterStartDate) >= 0) &&
|
||||
((filterEndDate == null) || day.compareTo(filterEndDate) <= 0) ) {
|
||||
|
||||
BigDecimal cost = advanceMeasurement.getValue().setScale(2)
|
||||
.multiply(new BigDecimal(totalHours))
|
||||
.divide(new BigDecimal(100),
|
||||
new MathContext(2, RoundingMode.HALF_UP));
|
||||
.divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_UP));
|
||||
result.put(day, cost);
|
||||
}
|
||||
}
|
||||
|
|
@ -98,37 +105,101 @@ public class HoursCostCalculator implements ICostCalculator {
|
|||
return getEstimatedCost(task, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* BCWS values are calculating here.
|
||||
* MAX(BCWS) equals addition of all dayAssignments.
|
||||
*/
|
||||
@Override
|
||||
public SortedMap<LocalDate, BigDecimal> getEstimatedCost(Task task,
|
||||
LocalDate filterStartDate, LocalDate filterEndDate) {
|
||||
if (task.isSubcontracted()) {
|
||||
public SortedMap<LocalDate, BigDecimal> getEstimatedCost(
|
||||
Task task,
|
||||
LocalDate filterStartDate,
|
||||
LocalDate filterEndDate) {
|
||||
|
||||
if ( task.isSubcontracted() ) {
|
||||
return getAdvanceCost(task);
|
||||
}
|
||||
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
|
||||
List<DayAssignment> dayAssignments = task
|
||||
.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
if (dayAssignments.isEmpty()) {
|
||||
List<DayAssignment> dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
if ( dayAssignments.isEmpty() ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int additionOfAllAssignmentsMinutes = 0;
|
||||
|
||||
for (DayAssignment dayAssignment : dayAssignments) {
|
||||
LocalDate day = dayAssignment.getDay();
|
||||
if(((filterStartDate == null) || day.compareTo(filterStartDate) >= 0) &&
|
||||
((filterEndDate == null) || day.compareTo(filterEndDate) <= 0)) {
|
||||
BigDecimal cost = new BigDecimal(dayAssignment.getHours());
|
||||
if( ( (filterStartDate == null) || day.compareTo(filterStartDate) >= 0) &&
|
||||
( (filterEndDate == null) || day.compareTo(filterEndDate) <= 0) ) {
|
||||
|
||||
if (!result.containsKey(day)) {
|
||||
String currentTime = dayAssignment.getDuration().toFormattedString();
|
||||
|
||||
|
||||
SimpleDateFormat format1 = new SimpleDateFormat("hh:mm");
|
||||
SimpleDateFormat format2 = new SimpleDateFormat("hh");
|
||||
|
||||
Date date = null;
|
||||
|
||||
try {
|
||||
if ( isParsableWithFormat1(currentTime) )
|
||||
date = format1.parse(currentTime);
|
||||
else if ( isParsableWithFormat2(currentTime) )
|
||||
date = format2.parse(currentTime);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Time time = new Time(date.getTime());
|
||||
|
||||
BigDecimal hours = new BigDecimal(time.getHours());
|
||||
additionOfAllAssignmentsMinutes += time.getMinutes();
|
||||
|
||||
if ( !result.containsKey(day) ) {
|
||||
result.put(day, BigDecimal.ZERO);
|
||||
}
|
||||
result.put(day, result.get(day).add(cost));
|
||||
|
||||
/**
|
||||
* On last day assignment app will check addition of minutes of all assignments.
|
||||
* If it is between 30 and 60 - add 1 hour to the last value of result.
|
||||
* If it is more than 60 then divide on 60 and calculate hours.
|
||||
* E.G. 120 minutes / 60 = 2 hours.
|
||||
*/
|
||||
if ( dayAssignment.equals(dayAssignments.get(dayAssignments.size() - 1)) ){
|
||||
|
||||
if ( additionOfAllAssignmentsMinutes >= 30 && additionOfAllAssignmentsMinutes <= 60 )
|
||||
hours = BigDecimal.valueOf(hours.intValue() + 1);
|
||||
|
||||
if ( additionOfAllAssignmentsMinutes > 60 )
|
||||
hours = BigDecimal.valueOf(hours.intValue() + (additionOfAllAssignmentsMinutes / 60));
|
||||
}
|
||||
result.put(day, result.get(day).add(hours));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isParsableWithFormat1(String input){
|
||||
boolean parsable = true;
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat("hh:mm");
|
||||
format.parse(input);
|
||||
} catch (ParseException e) {
|
||||
parsable = false;
|
||||
}
|
||||
return parsable;
|
||||
}
|
||||
private boolean isParsableWithFormat2(String input){
|
||||
boolean parsable = true;
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat("hh");
|
||||
format.parse(input);
|
||||
} catch (ParseException e) {
|
||||
parsable = false;
|
||||
}
|
||||
return parsable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<LocalDate, BigDecimal> getWorkReportCost(Task task) {
|
||||
if (task.isSubcontracted()) {
|
||||
|
|
|
|||
|
|
@ -32,13 +32,10 @@ import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
|||
*/
|
||||
public interface ICompanyEarnedValueCalculator extends IEarnedValueCalculator {
|
||||
|
||||
SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkScheduled(
|
||||
AvailabilityTimeLine.Interval interval);
|
||||
SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkScheduled(AvailabilityTimeLine.Interval interval);
|
||||
|
||||
SortedMap<LocalDate, BigDecimal> calculateActualCostWorkPerformed(
|
||||
AvailabilityTimeLine.Interval interval);
|
||||
SortedMap<LocalDate, BigDecimal> calculateActualCostWorkPerformed(AvailabilityTimeLine.Interval interval);
|
||||
|
||||
SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkPerformed(
|
||||
AvailabilityTimeLine.Interval interval);
|
||||
SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkPerformed(AvailabilityTimeLine.Interval interval);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,21 +52,19 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public SortedMap<LocalDate, BigDecimal> calculateActualCostWorkPerformed(
|
||||
Order order) {
|
||||
public SortedMap<LocalDate, BigDecimal> calculateActualCostWorkPerformed(Order order) {
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
for (TaskElement taskElement : getAllTaskElements(order)) {
|
||||
if (taskElement instanceof Task) {
|
||||
if ( taskElement instanceof Task ) {
|
||||
addCost(result, getWorkReportCost((Task) taskElement));
|
||||
}
|
||||
}
|
||||
return accumulateResult(result);
|
||||
}
|
||||
|
||||
private SortedMap<LocalDate, BigDecimal> accumulateResult(
|
||||
SortedMap<LocalDate, BigDecimal> map) {
|
||||
private SortedMap<LocalDate, BigDecimal> accumulateResult(SortedMap<LocalDate, BigDecimal> map) {
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
if (map.isEmpty()) {
|
||||
if ( map.isEmpty() ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -80,13 +78,13 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
}
|
||||
|
||||
private void addCost(SortedMap<LocalDate, BigDecimal> currentCost,
|
||||
SortedMap<LocalDate, BigDecimal> additionalCost) {
|
||||
SortedMap<LocalDate, BigDecimal> additionalCost) {
|
||||
|
||||
for (LocalDate day : additionalCost.keySet()) {
|
||||
if (!currentCost.containsKey(day)) {
|
||||
if ( !currentCost.containsKey(day) ) {
|
||||
currentCost.put(day, BigDecimal.ZERO);
|
||||
}
|
||||
currentCost.put(day,
|
||||
currentCost.get(day).add(additionalCost.get(day)));
|
||||
currentCost.put(day, currentCost.get(day).add(additionalCost.get(day)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,17 +102,15 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
@Transactional(readOnly = true)
|
||||
public BigDecimal getBudgetAtCompletion(Order order) {
|
||||
SortedMap<LocalDate, BigDecimal> budgedtedCost = calculateBudgetedCostWorkScheduled(order);
|
||||
return !budgedtedCost.isEmpty() ? budgedtedCost.get(budgedtedCost
|
||||
.lastKey()) : BigDecimal.ZERO;
|
||||
return !budgedtedCost.isEmpty() ? budgedtedCost.get(budgedtedCost.lastKey()) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkScheduled(
|
||||
Order order) {
|
||||
public SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkScheduled(Order order) {
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
for (TaskElement taskElement : getAllTaskElements(order)) {
|
||||
if (taskElement instanceof Task) {
|
||||
if ( taskElement instanceof Task ) {
|
||||
addCost(result, getEstimatedCost((Task) taskElement));
|
||||
}
|
||||
}
|
||||
|
|
@ -132,21 +128,20 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
return getValueAt(budgetedCost, date);
|
||||
}
|
||||
|
||||
private BigDecimal getValueAt(SortedMap<LocalDate, BigDecimal> map,
|
||||
LocalDate date) {
|
||||
if (map.isEmpty()) {
|
||||
private BigDecimal getValueAt(SortedMap<LocalDate, BigDecimal> map, LocalDate date) {
|
||||
if ( map.isEmpty() ) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal result = map.get(date);
|
||||
if (result != null) {
|
||||
if ( result != null ) {
|
||||
return result;
|
||||
}
|
||||
for (LocalDate each : map.keySet()) {
|
||||
if (date.isBefore(each)) {
|
||||
if ( date.isBefore(each) ) {
|
||||
return map.get(each);
|
||||
}
|
||||
}
|
||||
if (date.isAfter(map.lastKey())) {
|
||||
if ( date.isAfter(map.lastKey()) ) {
|
||||
return map.get(map.lastKey());
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
|
|
@ -154,11 +149,10 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkPerformed(
|
||||
Order order) {
|
||||
public SortedMap<LocalDate, BigDecimal> calculateBudgetedCostWorkPerformed(Order order) {
|
||||
SortedMap<LocalDate, BigDecimal> estimatedCost = new TreeMap<LocalDate, BigDecimal>();
|
||||
for (TaskElement taskElement : getAllTaskElements(order)) {
|
||||
if (taskElement instanceof Task) {
|
||||
if ( taskElement instanceof Task ) {
|
||||
addCost(estimatedCost, getAdvanceCost((Task) taskElement));
|
||||
}
|
||||
}
|
||||
|
|
@ -170,9 +164,8 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCostPerformanceIndex(BigDecimal budgetedCost,
|
||||
BigDecimal actualCost) {
|
||||
if (BigDecimal.ZERO.compareTo(actualCost) == 0) {
|
||||
public BigDecimal getCostPerformanceIndex(BigDecimal budgetedCost, BigDecimal actualCost) {
|
||||
if ( BigDecimal.ZERO.compareTo(actualCost) == 0 ) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return budgetedCost.setScale(4)
|
||||
|
|
@ -182,15 +175,13 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCostVariance(BigDecimal budgetedCost,
|
||||
BigDecimal actualCost) {
|
||||
public BigDecimal getCostVariance(BigDecimal budgetedCost, BigDecimal actualCost) {
|
||||
return budgetedCost.subtract(actualCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getEstimateAtCompletion(BigDecimal budgetAtCompletion,
|
||||
BigDecimal costPerformanceIndex) {
|
||||
if (BigDecimal.ZERO.compareTo(costPerformanceIndex) == 0) {
|
||||
public BigDecimal getEstimateAtCompletion(BigDecimal budgetAtCompletion, BigDecimal costPerformanceIndex) {
|
||||
if ( BigDecimal.ZERO.compareTo(costPerformanceIndex) == 0 ) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return budgetAtCompletion.setScale(2)
|
||||
|
|
@ -199,8 +190,7 @@ public class OrderEarnedValueCalculator extends EarnedValueCalculator implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getEstimateToComplete(BigDecimal estimateAtCompletion,
|
||||
BigDecimal actualCostWorkPerformed) {
|
||||
public BigDecimal getEstimateToComplete(BigDecimal estimateAtCompletion, BigDecimal actualCostWorkPerformed) {
|
||||
return estimateAtCompletion.subtract(actualCostWorkPerformed);
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -46,6 +46,7 @@ import org.libreplan.business.workingday.EffortDuration;
|
|||
public class SpecificDayAssignment extends DayAssignment {
|
||||
|
||||
private abstract class ParentState {
|
||||
|
||||
abstract SpecificResourceAllocation getResourceAllocation();
|
||||
|
||||
abstract ParentState setParent(
|
||||
|
|
@ -66,11 +67,9 @@ public class SpecificDayAssignment extends DayAssignment {
|
|||
}
|
||||
|
||||
@Override
|
||||
ParentState setParent(
|
||||
SpecificResourceAllocation specificResourceAllocation) {
|
||||
if (parent != null && parent != specificResourceAllocation) {
|
||||
throw new IllegalStateException(
|
||||
"the allocation cannot be changed once it has been set");
|
||||
ParentState setParent(SpecificResourceAllocation specificResourceAllocation) {
|
||||
if ( parent != null && parent != specificResourceAllocation ) {
|
||||
throw new IllegalStateException("the allocation cannot be changed once it has been set");
|
||||
}
|
||||
this.parent = specificResourceAllocation;
|
||||
return this;
|
||||
|
|
@ -121,9 +120,9 @@ public class SpecificDayAssignment extends DayAssignment {
|
|||
}
|
||||
|
||||
|
||||
public static Set<SpecificDayAssignment> copy(
|
||||
SpecificDayAssignmentsContainer container,
|
||||
Collection<? extends SpecificDayAssignment> specificDaysAssignment) {
|
||||
public static Set<SpecificDayAssignment> copy(SpecificDayAssignmentsContainer container,
|
||||
Collection<? extends SpecificDayAssignment> specificDaysAssignment) {
|
||||
|
||||
Set<SpecificDayAssignment> result = new HashSet<SpecificDayAssignment>();
|
||||
for (SpecificDayAssignment s : specificDaysAssignment) {
|
||||
SpecificDayAssignment created = copyFromWithoutParent(s);
|
||||
|
|
@ -135,16 +134,15 @@ public class SpecificDayAssignment extends DayAssignment {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static SpecificDayAssignment copyFromWithoutParent(
|
||||
SpecificDayAssignment assignment) {
|
||||
SpecificDayAssignment copy = create(assignment.getDay(),
|
||||
assignment.getDuration(), assignment.getResource());
|
||||
private static SpecificDayAssignment copyFromWithoutParent(SpecificDayAssignment assignment) {
|
||||
SpecificDayAssignment copy = create(assignment.getDay(), assignment.getDuration(), assignment.getResource());
|
||||
copy.setConsolidated(assignment.isConsolidated());
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static List<SpecificDayAssignment> copyToAssignmentsWithoutParent(
|
||||
Collection<? extends SpecificDayAssignment> assignments) {
|
||||
|
||||
List<SpecificDayAssignment> result = new ArrayList<SpecificDayAssignment>();
|
||||
for (SpecificDayAssignment each : assignments) {
|
||||
result.add(copyFromWithoutParent(each));
|
||||
|
|
|
|||
|
|
@ -38,14 +38,12 @@ import org.libreplan.business.workingday.IntraDayDate;
|
|||
* for a {@link ResourceAllocation} at a {@link Scenario} <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class SpecificDayAssignmentsContainer extends BaseEntity implements
|
||||
IDayAssignmentsContainer<SpecificDayAssignment> {
|
||||
public class SpecificDayAssignmentsContainer extends BaseEntity
|
||||
implements IDayAssignmentsContainer<SpecificDayAssignment> {
|
||||
|
||||
public static SpecificDayAssignmentsContainer create(
|
||||
SpecificResourceAllocation specificResourceAllocation,
|
||||
Scenario scenario) {
|
||||
return create(new SpecificDayAssignmentsContainer(specificResourceAllocation,
|
||||
scenario));
|
||||
public static SpecificDayAssignmentsContainer create(SpecificResourceAllocation specificResourceAllocation,
|
||||
Scenario scenario) {
|
||||
return create(new SpecificDayAssignmentsContainer(specificResourceAllocation, scenario));
|
||||
}
|
||||
|
||||
private SpecificResourceAllocation resourceAllocation;
|
||||
|
|
@ -71,8 +69,7 @@ public class SpecificDayAssignmentsContainer extends BaseEntity implements
|
|||
return new HashSet<SpecificDayAssignment>(dayAssignments);
|
||||
}
|
||||
|
||||
private SpecificDayAssignmentsContainer(
|
||||
SpecificResourceAllocation resourceAllocation, Scenario scenario) {
|
||||
private SpecificDayAssignmentsContainer(SpecificResourceAllocation resourceAllocation, Scenario scenario) {
|
||||
Validate.notNull(resourceAllocation);
|
||||
Validate.notNull(scenario);
|
||||
this.resourceAllocation = resourceAllocation;
|
||||
|
|
@ -112,8 +109,7 @@ public class SpecificDayAssignmentsContainer extends BaseEntity implements
|
|||
dayAssignments.addAll(copyToThisContainer(assignments));
|
||||
}
|
||||
|
||||
private Set<SpecificDayAssignment> copyToThisContainer(
|
||||
Collection<? extends SpecificDayAssignment> assignments) {
|
||||
private Set<SpecificDayAssignment> copyToThisContainer(Collection<? extends SpecificDayAssignment> assignments) {
|
||||
return SpecificDayAssignment.copy(this, assignments);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,12 +60,10 @@ import org.libreplan.business.workingday.ResourcesPerDay;
|
|||
* Represents the relation between {@link Task} and a specific {@link Worker}.
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class SpecificResourceAllocation extends
|
||||
ResourceAllocation<SpecificDayAssignment> implements IAllocatable {
|
||||
public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAssignment> implements IAllocatable {
|
||||
|
||||
public static SpecificResourceAllocation create(Task task) {
|
||||
return create(new SpecificResourceAllocation(
|
||||
task));
|
||||
return create(new SpecificResourceAllocation(task));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,11 +78,9 @@ public class SpecificResourceAllocation extends
|
|||
* @param task
|
||||
* @return
|
||||
*/
|
||||
public static SpecificResourceAllocation createForLimiting(Resource resource,
|
||||
Task task) {
|
||||
public static SpecificResourceAllocation createForLimiting(Resource resource, Task task) {
|
||||
assert resource.isLimitingResource();
|
||||
SpecificResourceAllocation result = create(new SpecificResourceAllocation(
|
||||
task));
|
||||
SpecificResourceAllocation result = create(new SpecificResourceAllocation(task));
|
||||
result.setResource(resource);
|
||||
result.setResourcesPerDayToAmount(1);
|
||||
return result;
|
||||
|
|
@ -96,42 +92,35 @@ public class SpecificResourceAllocation extends
|
|||
private Set<SpecificDayAssignmentsContainer> specificDayAssignmentsContainers = new HashSet<SpecificDayAssignmentsContainer>();
|
||||
|
||||
@Valid
|
||||
private Set<SpecificDayAssignmentsContainer> getSpecificDayAssignmentsContainers() {
|
||||
return new HashSet<SpecificDayAssignmentsContainer>(
|
||||
specificDayAssignmentsContainers);
|
||||
public Set<SpecificDayAssignmentsContainer> getSpecificDayAssignmentsContainers() {
|
||||
return new HashSet<SpecificDayAssignmentsContainer>(specificDayAssignmentsContainers);
|
||||
}
|
||||
|
||||
public static SpecificResourceAllocation createForTesting(
|
||||
ResourcesPerDay resourcesPerDay, Task task) {
|
||||
return create(new SpecificResourceAllocation(
|
||||
resourcesPerDay, task));
|
||||
public static SpecificResourceAllocation createForTesting(ResourcesPerDay resourcesPerDay, Task task) {
|
||||
return create(new SpecificResourceAllocation(resourcesPerDay, task));
|
||||
}
|
||||
|
||||
public SpecificResourceAllocation() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpecificDayAssignmentsContainer retrieveOrCreateContainerFor(
|
||||
Scenario scenario) {
|
||||
protected SpecificDayAssignmentsContainer retrieveOrCreateContainerFor(Scenario scenario) {
|
||||
SpecificDayAssignmentsContainer retrieved = retrieveContainerFor(scenario);
|
||||
if (retrieved != null) {
|
||||
if ( retrieved != null ) {
|
||||
return retrieved;
|
||||
}
|
||||
SpecificDayAssignmentsContainer result = SpecificDayAssignmentsContainer
|
||||
.create(this, scenario);
|
||||
SpecificDayAssignmentsContainer result = SpecificDayAssignmentsContainer.create(this, scenario);
|
||||
specificDayAssignmentsContainers.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpecificDayAssignmentsContainer retrieveContainerFor(
|
||||
Scenario scenario) {
|
||||
protected SpecificDayAssignmentsContainer retrieveContainerFor(Scenario scenario) {
|
||||
Map<Scenario, SpecificDayAssignmentsContainer> containers = containersByScenario();
|
||||
return containers.get(scenario);
|
||||
}
|
||||
|
||||
private SpecificResourceAllocation(ResourcesPerDay resourcesPerDay,
|
||||
Task task) {
|
||||
private SpecificResourceAllocation(ResourcesPerDay resourcesPerDay, Task task) {
|
||||
super(resourcesPerDay, task);
|
||||
}
|
||||
|
||||
|
|
@ -165,15 +154,12 @@ public class SpecificResourceAllocation extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public IAllocateResourcesPerDay resourcesPerDayUntil(
|
||||
IntraDayDate endExclusive) {
|
||||
return new SpecificAssignmentsAllocator()
|
||||
.resourcesPerDayUntil(endExclusive);
|
||||
public IAllocateResourcesPerDay resourcesPerDayUntil(IntraDayDate endExclusive) {
|
||||
return new SpecificAssignmentsAllocator().resourcesPerDayUntil(endExclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateResourcesPerDay resourcesPerDayFromEndUntil(
|
||||
IntraDayDate start) {
|
||||
public IAllocateResourcesPerDay resourcesPerDayFromEndUntil(IntraDayDate start) {
|
||||
SpecificAssignmentsAllocator allocator = new SpecificAssignmentsAllocator();
|
||||
return allocator.resourcesPerDayFromEndUntil(start);
|
||||
}
|
||||
|
|
@ -192,10 +178,8 @@ public class SpecificResourceAllocation extends
|
|||
AssignmentsAllocator {
|
||||
|
||||
@Override
|
||||
public List<SpecificDayAssignment> distributeForDay(PartialDay day,
|
||||
EffortDuration effort) {
|
||||
return Arrays.asList(SpecificDayAssignment.create(day.getDate(),
|
||||
effort, resource));
|
||||
public List<SpecificDayAssignment> distributeForDay(PartialDay day, EffortDuration effort) {
|
||||
return Arrays.asList(SpecificDayAssignment.create(day.getDate(), effort, resource));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -221,29 +205,23 @@ public class SpecificResourceAllocation extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public IAllocateEffortOnInterval onIntervalWithinTask(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
return new SpecificAssignmentsAllocator().onIntervalWithinTask(start,
|
||||
end);
|
||||
public IAllocateEffortOnInterval onIntervalWithinTask(IntraDayDate start, IntraDayDate end) {
|
||||
return new SpecificAssignmentsAllocator().onIntervalWithinTask(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateEffortOnInterval onInterval(LocalDate startInclusive,
|
||||
LocalDate endExclusive) {
|
||||
return new SpecificAssignmentsAllocator().onInterval(startInclusive,
|
||||
endExclusive);
|
||||
public IAllocateEffortOnInterval onInterval(LocalDate startInclusive, LocalDate endExclusive) {
|
||||
return new SpecificAssignmentsAllocator().onInterval(startInclusive, endExclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateEffortOnInterval onInterval(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
public IAllocateEffortOnInterval onInterval(IntraDayDate start, IntraDayDate end) {
|
||||
return new SpecificAssignmentsAllocator().onInterval(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ICalendar getCalendarGivenTaskCalendar(ICalendar taskCalendar) {
|
||||
return CombinedWorkHours.minOf(taskCalendar, getResource()
|
||||
.getCalendar());
|
||||
return CombinedWorkHours.minOf(taskCalendar, getResource().getCalendar());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -327,39 +305,35 @@ public class SpecificResourceAllocation extends
|
|||
* @param effortForNotConsolidatedPart
|
||||
* @param endExclusive
|
||||
*/
|
||||
public void allocateWholeAllocationKeepingProportions(
|
||||
EffortDuration effortForNotConsolidatedPart, IntraDayDate end) {
|
||||
AllocationInterval interval = new AllocationInterval(
|
||||
getIntraDayStartDate(), end);
|
||||
public void allocateWholeAllocationKeepingProportions(EffortDuration effortForNotConsolidatedPart,
|
||||
IntraDayDate end) {
|
||||
|
||||
List<DayAssignment> nonConsolidatedAssignments = interval
|
||||
.getNoConsolidatedAssignmentsOnInterval();
|
||||
ProportionalDistributor distributor = ProportionalDistributor
|
||||
.create(asSeconds(nonConsolidatedAssignments));
|
||||
AllocationInterval interval = new AllocationInterval(getIntraDayStartDate(), end);
|
||||
|
||||
EffortDuration[] effortsPerDay = asEfforts(distributor
|
||||
.distribute(effortForNotConsolidatedPart.getSeconds()));
|
||||
allocateTheWholeAllocation(
|
||||
interval,
|
||||
assignmentsForEfforts(nonConsolidatedAssignments, effortsPerDay));
|
||||
List<DayAssignment> nonConsolidatedAssignments = interval.getNoConsolidatedAssignmentsOnInterval();
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(asSeconds(nonConsolidatedAssignments));
|
||||
|
||||
EffortDuration[] effortsPerDay = asEfforts(distributor.distribute(effortForNotConsolidatedPart.getSeconds()));
|
||||
allocateTheWholeAllocation(interval, assignmentsForEfforts(nonConsolidatedAssignments, effortsPerDay));
|
||||
}
|
||||
|
||||
private EffortDuration[] asEfforts(int[] secondsArray) {
|
||||
EffortDuration[] result = new EffortDuration[secondsArray.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = EffortDuration.seconds(secondsArray[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<SpecificDayAssignment> assignmentsForEfforts(
|
||||
List<DayAssignment> assignments, EffortDuration[] newEffortsPerDay) {
|
||||
private List<SpecificDayAssignment> assignmentsForEfforts(List<DayAssignment> assignments,
|
||||
EffortDuration[] newEffortsPerDay) {
|
||||
|
||||
List<SpecificDayAssignment> result = new ArrayList<SpecificDayAssignment>();
|
||||
int i = 0;
|
||||
for (DayAssignment each : assignments) {
|
||||
EffortDuration durationForAssignment = newEffortsPerDay[i++];
|
||||
result.add(SpecificDayAssignment.create(each.getDay(),
|
||||
durationForAssignment, resource));
|
||||
result.add(SpecificDayAssignment.create(each.getDay(), durationForAssignment, resource));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -367,35 +341,32 @@ public class SpecificResourceAllocation extends
|
|||
private int[] asSeconds(List<DayAssignment> assignments) {
|
||||
int[] result = new int[assignments.size()];
|
||||
int i = 0;
|
||||
|
||||
for (DayAssignment each : assignments) {
|
||||
result[i++] = each.getDuration().getSeconds();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void overrideConsolidatedDayAssignments(
|
||||
SpecificResourceAllocation origin) {
|
||||
if (origin != null) {
|
||||
List<SpecificDayAssignment> originAssignments = origin
|
||||
.getConsolidatedAssignments();
|
||||
resetAssignmentsTo(SpecificDayAssignment
|
||||
.copyToAssignmentsWithoutParent(originAssignments));
|
||||
public void overrideConsolidatedDayAssignments(SpecificResourceAllocation origin) {
|
||||
if ( origin != null ) {
|
||||
List<SpecificDayAssignment> originAssignments = origin.getConsolidatedAssignments();
|
||||
resetAssignmentsTo(SpecificDayAssignment.copyToAssignmentsWithoutParent(originAssignments));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EffortDuration getAssignedEffort(Criterion criterion,
|
||||
final IntraDayDate startInclusive, final IntraDayDate endExclusive) {
|
||||
public EffortDuration getAssignedEffort(Criterion criterion, final IntraDayDate startInclusive,
|
||||
final IntraDayDate endExclusive) {
|
||||
|
||||
return EffortDuration.sum(
|
||||
getIntervalsRelatedWith(criterion, startInclusive.getDate(),
|
||||
endExclusive.asExclusiveEnd()),
|
||||
new IEffortFrom<Interval>() {
|
||||
return EffortDuration.sum(getIntervalsRelatedWith(criterion, startInclusive.getDate(),
|
||||
endExclusive.asExclusiveEnd()), new IEffortFrom<Interval>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration from(Interval each) {
|
||||
FixedPoint intervalStart = (FixedPoint) each.getStart();
|
||||
FixedPoint intervalEnd = (FixedPoint) each.getEnd();
|
||||
|
||||
return getAssignedDuration(
|
||||
IntraDayDate.convert(intervalStart.getDate(), startInclusive),
|
||||
IntraDayDate.convert(intervalEnd.getDate(), endExclusive));
|
||||
|
|
@ -403,34 +374,32 @@ public class SpecificResourceAllocation extends
|
|||
});
|
||||
}
|
||||
|
||||
private List<Interval> getIntervalsRelatedWith(Criterion criterion,
|
||||
LocalDate startInclusive, LocalDate endExclusive) {
|
||||
Interval queryInterval = AvailabilityTimeLine.Interval.create(
|
||||
startInclusive, endExclusive);
|
||||
private List<Interval> getIntervalsRelatedWith(Criterion criterion, LocalDate startInclusive,
|
||||
LocalDate endExclusive) {
|
||||
|
||||
Interval queryInterval = AvailabilityTimeLine.Interval.create(startInclusive, endExclusive);
|
||||
|
||||
List<Interval> result = new ArrayList<Interval>();
|
||||
|
||||
for (Interval each : getIntervalsThisAllocationInterferesWith(criterion)) {
|
||||
if (queryInterval.overlaps(each)) {
|
||||
if ( queryInterval.overlaps(each) ) {
|
||||
result.add(queryInterval.intersect(each));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Interval> getIntervalsThisAllocationInterferesWith(
|
||||
Criterion criterion) {
|
||||
AvailabilityTimeLine availability = AvailabilityCalculator
|
||||
.getCriterionsAvailabilityFor(Collections.singleton(criterion),
|
||||
resource);
|
||||
private List<Interval> getIntervalsThisAllocationInterferesWith(Criterion criterion) {
|
||||
AvailabilityTimeLine availability =
|
||||
AvailabilityCalculator.getCriterionsAvailabilityFor(Collections.singleton(criterion), resource);
|
||||
|
||||
availability.invalidUntil(getStartDate());
|
||||
availability.invalidFrom(getEndDate());
|
||||
return availability.getValidPeriods();
|
||||
}
|
||||
|
||||
public boolean interferesWith(Criterion criterion,
|
||||
LocalDate startInclusive, LocalDate endExclusive) {
|
||||
List<Interval> intervalsRelatedWith = getIntervalsRelatedWith(
|
||||
criterion, startInclusive, endExclusive);
|
||||
public boolean interferesWith(Criterion criterion, LocalDate startInclusive, LocalDate endExclusive) {
|
||||
List<Interval> intervalsRelatedWith = getIntervalsRelatedWith(criterion, startInclusive, endExclusive);
|
||||
return !intervalsRelatedWith.isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
private Set<ResourceAllocation<?>> resourceAllocations = new HashSet<ResourceAllocation<?>>();
|
||||
|
||||
@Valid
|
||||
private Set<ResourceAllocation<?>> getResourceAlloations() {
|
||||
private Set<ResourceAllocation<?>> getResourceAllocations() {
|
||||
return new HashSet<ResourceAllocation<?>>(resourceAllocations);
|
||||
}
|
||||
|
||||
|
|
@ -238,11 +238,10 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
public Set<ResourceAllocation<?>> getSatisfiedResourceAllocations() {
|
||||
Set<ResourceAllocation<?>> result = new HashSet<ResourceAllocation<?>>();
|
||||
|
||||
if (isLimiting()) {
|
||||
if ( isLimiting() ) {
|
||||
result.addAll(getLimitingResourceAllocations());
|
||||
} else {
|
||||
result.addAll(ResourceAllocation
|
||||
.getSatisfied(resourceAllocations));
|
||||
result.addAll(ResourceAllocation.getSatisfied(resourceAllocations));
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
|
@ -282,31 +281,27 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
}
|
||||
|
||||
public LimitingResourceQueueElement getAssociatedLimitingResourceQueueElementIfAny() {
|
||||
if (!isLimiting()) {
|
||||
if ( !isLimiting() ) {
|
||||
throw new IllegalStateException("this is not a limiting task");
|
||||
}
|
||||
return getAssociatedLimitingResourceAllocation()
|
||||
.getLimitingResourceQueueElement();
|
||||
return getAssociatedLimitingResourceAllocation().getLimitingResourceQueueElement();
|
||||
}
|
||||
|
||||
public boolean isLimitingAndHasDayAssignments() {
|
||||
ResourceAllocation<?> resourceAllocation = getAssociatedLimitingResourceAllocation();
|
||||
return resourceAllocation != null
|
||||
&& resourceAllocation.isLimitingAndHasDayAssignments();
|
||||
return resourceAllocation != null && resourceAllocation.isLimitingAndHasDayAssignments();
|
||||
}
|
||||
|
||||
public void addResourceAllocation(ResourceAllocation<?> resourceAllocation) {
|
||||
addResourceAllocation(resourceAllocation, true);
|
||||
}
|
||||
|
||||
public void addResourceAllocation(ResourceAllocation<?> resourceAllocation,
|
||||
boolean generateDayAssignments) {
|
||||
if (!resourceAllocation.getTask().equals(this)) {
|
||||
throw new IllegalArgumentException(
|
||||
"the resourceAllocation's task must be this task");
|
||||
public void addResourceAllocation(ResourceAllocation<?> resourceAllocation, boolean generateDayAssignments) {
|
||||
if ( !resourceAllocation.getTask().equals(this) ) {
|
||||
throw new IllegalArgumentException("the resourceAllocation's task must be this task");
|
||||
}
|
||||
resourceAllocations.add(resourceAllocation);
|
||||
if (generateDayAssignments) {
|
||||
if ( generateDayAssignments ) {
|
||||
resourceAllocation.associateAssignmentsToResource();
|
||||
}
|
||||
}
|
||||
|
|
@ -795,18 +790,15 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
new WithPotentiallyNewResources(searcher));
|
||||
}
|
||||
|
||||
private void reassign(Scenario onScenario, Direction direction,
|
||||
WithPotentiallyNewResources strategy) {
|
||||
private void reassign(Scenario onScenario, Direction direction, WithPotentiallyNewResources strategy) {
|
||||
try {
|
||||
this.lastAllocationDirection = direction;
|
||||
if (isLimiting()) {
|
||||
if ( isLimiting() ) {
|
||||
return;
|
||||
}
|
||||
List<ModifiedAllocation> copied = ModifiedAllocation.copy(onScenario,
|
||||
getResourceAlloations());
|
||||
List<ResourceAllocation<?>> toBeModified = ModifiedAllocation
|
||||
.modified(copied);
|
||||
if (toBeModified.isEmpty()) {
|
||||
List<ModifiedAllocation> copied = ModifiedAllocation.copy(onScenario, getResourceAllocations());
|
||||
List<ResourceAllocation<?>> toBeModified = ModifiedAllocation.modified(copied);
|
||||
if ( toBeModified.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
setCustomAssignedEffortForResource(copied);
|
||||
|
|
@ -814,12 +806,12 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
updateDerived(copied);
|
||||
|
||||
List<ResourceAllocation<?>> newAllocations = emptyList(), removedAllocations = emptyList();
|
||||
mergeAllocation(onScenario, getIntraDayStartDate(),
|
||||
getIntraDayEndDate(), workableDays, calculatedValue,
|
||||
|
||||
mergeAllocation(onScenario, getIntraDayStartDate(), getIntraDayEndDate(), workableDays, calculatedValue,
|
||||
newAllocations, copied, removedAllocations);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("reassignment for task: " + this
|
||||
+ " couldn't be completed", e);
|
||||
LOG.error("reassignment for task: " + this + " couldn't be completed", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1186,7 +1178,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
if (this.currentStatus != null) {
|
||||
return this.currentStatus == TaskStatusEnum.IN_PROGRESS;
|
||||
} else {
|
||||
boolean advanceBetweenZeroAndOne = this.advancePertentageIsGreaterThanZero() &&
|
||||
boolean advanceBetweenZeroAndOne = this.advancePercentageIsGreaterThanZero() &&
|
||||
!advancePercentageIsOne();
|
||||
boolean outcome = advanceBetweenZeroAndOne || this.hasAttachedWorkReports();
|
||||
if (outcome == true) {
|
||||
|
|
@ -1197,19 +1189,18 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
}
|
||||
|
||||
public boolean isReadyToStart() {
|
||||
if (!this.advancePercentageIsZero() || this.hasAttachedWorkReports()) {
|
||||
if ( !this.advancePercentageIsZero() || this.hasAttachedWorkReports() ) {
|
||||
return false;
|
||||
}
|
||||
Set<Dependency> dependencies = getDependenciesWithThisDestinationAndAllParents();
|
||||
for (Dependency dependency: dependencies) {
|
||||
Type dependencyType = dependency.getType();
|
||||
if (dependencyType.equals(Type.END_START)) {
|
||||
if (!dependency.getOrigin().isFinished()) {
|
||||
if ( dependencyType.equals(Type.END_START) ) {
|
||||
if ( !dependency.getOrigin().isFinished() ) {
|
||||
return false;
|
||||
}
|
||||
} else if (dependencyType.equals(Type.START_START)) {
|
||||
if (!dependency.getOrigin().isFinished() &&
|
||||
!dependency.getOrigin().isInProgress()) {
|
||||
} else if ( dependencyType.equals(Type.START_START) ) {
|
||||
if ( !dependency.getOrigin().isFinished() && !dependency.getOrigin().isInProgress() ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1218,19 +1209,18 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
if (!this.advancePercentageIsZero() || this.hasAttachedWorkReports()) {
|
||||
if ( !this.advancePercentageIsZero() || this.hasAttachedWorkReports() ) {
|
||||
return false;
|
||||
}
|
||||
Set<Dependency> dependencies = getDependenciesWithThisDestinationAndAllParents();
|
||||
for (Dependency dependency: dependencies) {
|
||||
Type dependencyType = dependency.getType();
|
||||
if (dependencyType.equals(Type.END_START)) {
|
||||
if (!dependency.getOrigin().isFinished()) {
|
||||
if ( dependencyType.equals(Type.END_START) ) {
|
||||
if ( !dependency.getOrigin().isFinished() ) {
|
||||
return true;
|
||||
}
|
||||
} else if (dependencyType.equals(Type.START_START)) {
|
||||
if (!dependency.getOrigin().isFinished() &&
|
||||
!dependency.getOrigin().isInProgress()) {
|
||||
} else if ( dependencyType.equals(Type.START_START) ) {
|
||||
if ( !dependency.getOrigin().isFinished() && !dependency.getOrigin().isInProgress() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1238,7 +1228,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean advancePertentageIsGreaterThanZero() {
|
||||
private boolean advancePercentageIsGreaterThanZero() {
|
||||
return this.getAdvancePercentage().compareTo(BigDecimal.ZERO) > 0;
|
||||
}
|
||||
|
||||
|
|
@ -1270,4 +1260,13 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
return getPositionConstraint().getConstraintType().equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(TaskGroup taskGroup) {
|
||||
super.setParent(taskGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskSource(TaskSource taskSource) {
|
||||
super.setTaskSource(taskSource);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,14 +135,13 @@ public abstract class TaskElement extends BaseEntity {
|
|||
return this.getEndAsLocalDate();
|
||||
}
|
||||
|
||||
protected static <T extends TaskElement> T create(T taskElement,
|
||||
TaskSource taskSource) {
|
||||
protected static <T extends TaskElement> T create(T taskElement, TaskSource taskSource) {
|
||||
taskElement.setTaskSource(taskSource);
|
||||
taskElement.updateDeadlineFromOrderElement();
|
||||
taskElement.setName(taskElement.getOrderElement().getName());
|
||||
taskElement.updateAdvancePercentageFromOrderElement();
|
||||
Order order = taskElement.getOrderElement().getOrder();
|
||||
if (order.isScheduleBackwards()) {
|
||||
if ( order.isScheduleBackwards() ) {
|
||||
taskElement.setEndDate(order.getDeadline());
|
||||
} else {
|
||||
taskElement.setStartDate(order.getInitDate());
|
||||
|
|
@ -317,35 +316,31 @@ public abstract class TaskElement extends BaseEntity {
|
|||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
setIntraDayStartDate(IntraDayDate.startOfDay(LocalDate
|
||||
.fromDateFields(startDate)));
|
||||
setIntraDayStartDate(IntraDayDate.startOfDay(LocalDate.fromDateFields(startDate)));
|
||||
}
|
||||
|
||||
public void setIntraDayStartDate(IntraDayDate startDate) {
|
||||
if (startDate == null) {
|
||||
if ( startDate == null ) {
|
||||
LOG.error(doNotProvideNullsDiscouragingMessage());
|
||||
}
|
||||
IntraDayDate previousStart = getIntraDayStartDate();
|
||||
IntraDayDate previousEnd = getIntraDayEndDate();
|
||||
this.startDate = startDate;
|
||||
datesInterceptor.setStartDate(previousStart, previousEnd,
|
||||
getIntraDayStartDate());
|
||||
datesInterceptor.setStartDate(previousStart, previousEnd, getIntraDayStartDate());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Date getEndDate() {
|
||||
return endDate != null ? endDate.toDateTimeAtStartOfDay().toDate()
|
||||
: null;
|
||||
return (endDate != null) ? endDate.toDateTimeAtStartOfDay().toDate() : null;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
setIntraDayEndDate(endDate != null ? IntraDayDate.create(
|
||||
LocalDate.fromDateFields(endDate), EffortDuration.zero())
|
||||
: null);
|
||||
setIntraDayEndDate( (endDate != null) ?
|
||||
IntraDayDate.create(LocalDate.fromDateFields(endDate), EffortDuration.zero()) : null);
|
||||
}
|
||||
|
||||
public void setIntraDayEndDate(IntraDayDate endDate) {
|
||||
if (endDate == null) {
|
||||
if ( endDate == null ) {
|
||||
LOG.error(doNotProvideNullsDiscouragingMessage());
|
||||
}
|
||||
IntraDayDate previousEnd = getIntraDayEndDate();
|
||||
|
|
@ -576,20 +571,19 @@ public abstract class TaskElement extends BaseEntity {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void addToResult(SortedMap<LocalDate, EffortDuration> result,
|
||||
LocalDate date, EffortDuration duration) {
|
||||
EffortDuration current = result.get(date) != null ? result.get(date)
|
||||
: zero();
|
||||
private void addToResult(SortedMap<LocalDate, EffortDuration> result, LocalDate date, EffortDuration duration) {
|
||||
EffortDuration current = result.get(date) != null ? result.get(date) : zero();
|
||||
result.put(date, current.plus(duration));
|
||||
}
|
||||
|
||||
public List<DayAssignment> getDayAssignments(DayAssignment.FilterType filter) {
|
||||
List<DayAssignment> dayAssignments = new ArrayList<DayAssignment>();
|
||||
Set<ResourceAllocation<?>> resourceAllocations = getSatisfiedResourceAllocations();
|
||||
|
||||
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
|
||||
dayAssignments.addAll(resourceAllocation.getAssignments());
|
||||
Set<DerivedAllocation> derivedAllocations = resourceAllocation
|
||||
.getDerivedAllocations();
|
||||
Set<DerivedAllocation> derivedAllocations = resourceAllocation.getDerivedAllocations();
|
||||
|
||||
for (DerivedAllocation each : derivedAllocations) {
|
||||
dayAssignments.addAll(each.getAssignments());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,17 +194,21 @@ public class TaskGroup extends TaskElement {
|
|||
public void setTaskChildrenTo(List<TaskElement> children) {
|
||||
Validate.noNullElements(children);
|
||||
int positionOnTaskElements = 0;
|
||||
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
TaskElement element = children.get(i);
|
||||
element.setParent(this);
|
||||
if (positionOnTaskElements >= taskElements.size()) {
|
||||
|
||||
if ( positionOnTaskElements >= taskElements.size() ) {
|
||||
taskElements.add(element);
|
||||
} else {
|
||||
while (positionOnTaskElements < taskElements.size()
|
||||
&& isMilestone(taskElements.get(positionOnTaskElements))) {
|
||||
while (positionOnTaskElements < taskElements.size() &&
|
||||
isMilestone(taskElements.get(positionOnTaskElements))) {
|
||||
|
||||
positionOnTaskElements++;
|
||||
}
|
||||
if (positionOnTaskElements >= taskElements.size()) {
|
||||
|
||||
if ( positionOnTaskElements >= taskElements.size() ) {
|
||||
taskElements.add(element);
|
||||
} else {
|
||||
taskElements.set(positionOnTaskElements, element);
|
||||
|
|
@ -212,11 +216,10 @@ public class TaskGroup extends TaskElement {
|
|||
}
|
||||
positionOnTaskElements++;
|
||||
}
|
||||
ListIterator<TaskElement> listIterator = taskElements
|
||||
.listIterator(positionOnTaskElements);
|
||||
ListIterator<TaskElement> listIterator = taskElements.listIterator(positionOnTaskElements);
|
||||
while (listIterator.hasNext()) {
|
||||
TaskElement current = listIterator.next();
|
||||
if (!isMilestone(current)) {
|
||||
if ( !isMilestone(current) ) {
|
||||
listIterator.remove();
|
||||
}
|
||||
}
|
||||
|
|
@ -344,10 +347,10 @@ public class TaskGroup extends TaskElement {
|
|||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (this.isFinished == null) {
|
||||
if ( this.isFinished == null ) {
|
||||
this.isFinished = new Boolean(true);
|
||||
for (TaskElement each: taskElements) {
|
||||
if (!each.isFinished()) {
|
||||
if ( !each.isFinished() ) {
|
||||
this.isFinished = new Boolean(false);
|
||||
break;
|
||||
}
|
||||
|
|
@ -390,4 +393,8 @@ public class TaskGroup extends TaskElement {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskSource(TaskSource taskSource) {
|
||||
super.setTaskSource(taskSource);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ import org.libreplan.business.resources.daos.ICriterionDAO;
|
|||
public class Criterion extends IntegrationEntity implements ICriterion,
|
||||
Comparable<Criterion> {
|
||||
|
||||
public static Criterion createUnvalidated(String code, String name,
|
||||
CriterionType type, Criterion parent, Boolean active) {
|
||||
public static Criterion createUnvalidated(String code, String name, CriterionType type, Criterion parent,
|
||||
Boolean active) {
|
||||
|
||||
Criterion criterion = create(new Criterion(), code);
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ public class Criterion extends IntegrationEntity implements ICriterion,
|
|||
criterion.type = type;
|
||||
criterion.parent = parent;
|
||||
|
||||
if (active != null) {
|
||||
if ( active != null ) {
|
||||
criterion.active = active;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,8 +75,7 @@ import org.libreplan.business.workingday.IntraDayDate.PartialDay;
|
|||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
public abstract class Resource extends IntegrationEntity implements
|
||||
IHumanIdentifiable, Comparable<Resource> {
|
||||
public abstract class Resource extends IntegrationEntity implements IHumanIdentifiable, Comparable<Resource> {
|
||||
|
||||
public static class AllResourceAssignments implements IAssignmentsOnResourceCalculator {
|
||||
|
||||
|
|
@ -86,8 +85,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
}
|
||||
}
|
||||
|
||||
public static List<Machine> machines(
|
||||
Collection<? extends Resource> resources) {
|
||||
public static List<Machine> machines(Collection<? extends Resource> resources) {
|
||||
return filter(Machine.class, resources);
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +93,10 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
return filter(Worker.class, resources);
|
||||
}
|
||||
|
||||
public static <T extends Resource> List<T> filter(Class<T> klass,
|
||||
Collection<? extends Resource> resources) {
|
||||
public static <T extends Resource> List<T> filter(Class<T> klass, Collection<? extends Resource> resources) {
|
||||
List<T> result = new ArrayList<T>();
|
||||
for (Resource each : resources) {
|
||||
if (klass.isInstance(each)) {
|
||||
if ( klass.isInstance(each) ) {
|
||||
result.add(klass.cast(each));
|
||||
}
|
||||
}
|
||||
|
|
@ -150,11 +147,11 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
}
|
||||
|
||||
private List<DayAssignment> getAssignmentsForDay(LocalDate date) {
|
||||
if (assignmentsByDayCached == null) {
|
||||
if ( assignmentsByDayCached == null ) {
|
||||
assignmentsByDayCached = DayAssignment.byDay(getAssignments());
|
||||
}
|
||||
List<DayAssignment> list = assignmentsByDayCached.get(date);
|
||||
if (list == null){
|
||||
if ( list == null ){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return list;
|
||||
|
|
@ -167,7 +164,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
abstract List<DayAssignment> calculateAssignments();
|
||||
|
||||
List<DayAssignment> getAssignments() {
|
||||
if (cachedAssignments != null) {
|
||||
if ( cachedAssignments != null ) {
|
||||
return cachedAssignments;
|
||||
}
|
||||
return cachedAssignments = calculateAssignments();
|
||||
|
|
@ -185,8 +182,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
List<DayAssignment> result = new ArrayList<DayAssignment>();
|
||||
Scenario current = Registry.getScenarioManager().getCurrent();
|
||||
for (DayAssignment each : dayAssignments) {
|
||||
if (each.getScenario() != null
|
||||
&& each.getScenario().equals(current)) {
|
||||
if ( each.getScenario() != null && each.getScenario().equals(current) ) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
|
|
@ -206,8 +202,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
List<DayAssignment> calculateAssignments() {
|
||||
List<DayAssignment> result = new ArrayList<DayAssignment>();
|
||||
for (DayAssignment each : dayAssignments) {
|
||||
if (isTransient(each)
|
||||
|| each.getScenario().equals(currentScenario)) {
|
||||
if ( isTransient(each) || each.getScenario().equals(currentScenario) ) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
|
|
@ -223,32 +218,28 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
|
||||
@Valid
|
||||
public Set<CriterionSatisfaction> getCriterionSatisfactions() {
|
||||
Set<CriterionSatisfaction> satisfactionActives =
|
||||
new HashSet<CriterionSatisfaction>();
|
||||
Set<CriterionSatisfaction> satisfactionActives = new HashSet<CriterionSatisfaction>();
|
||||
for(CriterionSatisfaction satisfaction:criterionSatisfactions){
|
||||
if(!satisfaction.isIsDeleted()) {
|
||||
if( !satisfaction.isIsDeleted() ) {
|
||||
satisfactionActives.add(satisfaction);
|
||||
}
|
||||
}
|
||||
return satisfactionActives;
|
||||
}
|
||||
|
||||
public CriterionSatisfaction getCriterionSatisfactionByCode(String code)
|
||||
throws InstanceNotFoundException {
|
||||
public CriterionSatisfaction getCriterionSatisfactionByCode(String code) throws InstanceNotFoundException {
|
||||
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new InstanceNotFoundException(code,
|
||||
CriterionSatisfaction.class.getName());
|
||||
if ( StringUtils.isBlank(code) ) {
|
||||
throw new InstanceNotFoundException(code, CriterionSatisfaction.class.getName());
|
||||
}
|
||||
|
||||
for (CriterionSatisfaction i : criterionSatisfactions) {
|
||||
if (i.getCode().equalsIgnoreCase(StringUtils.trim(code))) {
|
||||
if ( i.getCode().equalsIgnoreCase(StringUtils.trim(code)) ) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InstanceNotFoundException(code,
|
||||
CriterionSatisfaction.class.getName());
|
||||
throw new InstanceNotFoundException(code, CriterionSatisfaction.class.getName());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -858,11 +849,11 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
public EffortDuration getAssignedDurationDiscounting(
|
||||
Map<Long, Set<BaseEntity>> allocationsFromWhichDiscountHours,
|
||||
LocalDate day) {
|
||||
|
||||
EffortDuration result = zero();
|
||||
for (DayAssignment dayAssignment : getAssignmentsForDay(day)) {
|
||||
|
||||
if (!dayAssignment
|
||||
.belongsToSomeOf(allocationsFromWhichDiscountHours)) {
|
||||
if ( !dayAssignment.belongsToSomeOf(allocationsFromWhichDiscountHours) ) {
|
||||
result = result.plus(dayAssignment.getDuration());
|
||||
}
|
||||
}
|
||||
|
|
@ -876,8 +867,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
this.dayAssignments.addAll(assignments);
|
||||
}
|
||||
|
||||
public void removeAssignments(
|
||||
Collection<? extends DayAssignment> assignments) {
|
||||
public void removeAssignments(Collection<? extends DayAssignment> assignments) {
|
||||
Validate.noNullElements(assignments);
|
||||
clearCachedData();
|
||||
this.dayAssignments.removeAll(assignments);
|
||||
|
|
@ -957,24 +947,25 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
//Create a newList with new Satisfactions and the old satisfactions
|
||||
Set<CriterionSatisfaction> newList = new HashSet<CriterionSatisfaction>(addlist);
|
||||
for(CriterionSatisfaction satisfaction : criterionSatisfactions){
|
||||
if(!newList.contains(satisfaction)){
|
||||
if( !newList.contains(satisfaction) ){
|
||||
newList.add(satisfaction);
|
||||
}
|
||||
}
|
||||
|
||||
//Create a activeList with not eliminated Satifaction
|
||||
Set<CriterionSatisfaction> activeList = new HashSet<CriterionSatisfaction>();
|
||||
for(CriterionSatisfaction satisfaction : addlist){
|
||||
if(!satisfaction.isIsDeleted()){
|
||||
if( !satisfaction.isIsDeleted() ){
|
||||
activeList.add(satisfaction);
|
||||
}
|
||||
}
|
||||
|
||||
validateSatisfactions(activeList);
|
||||
criterionSatisfactions.clear();
|
||||
criterionSatisfactions.addAll(newList);
|
||||
}
|
||||
|
||||
private void validateSatisfactions(Set<CriterionSatisfaction> satisfactions)
|
||||
throws ValidationException {
|
||||
private void validateSatisfactions(Set<CriterionSatisfaction> satisfactions) throws ValidationException {
|
||||
for (CriterionSatisfaction satisfaction : satisfactions) {
|
||||
final Set<CriterionSatisfaction> remainingSatisfactions = new HashSet<CriterionSatisfaction>();
|
||||
remainingSatisfactions.addAll(satisfactions);
|
||||
|
|
@ -983,15 +974,12 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
}
|
||||
}
|
||||
|
||||
private void validateSatisfaction(CriterionSatisfaction satisfaction,
|
||||
Set<CriterionSatisfaction> satisfactions)
|
||||
private void validateSatisfaction(CriterionSatisfaction satisfaction, Set<CriterionSatisfaction> satisfactions)
|
||||
throws ValidationException {
|
||||
|
||||
if (!canAddSatisfaction(satisfaction, satisfactions)) {
|
||||
String message = getReasonForNotAddingSatisfaction(satisfaction
|
||||
.getCriterion().getType());
|
||||
throw new ValidationException(invalidValue(message, "resource",
|
||||
this, satisfaction));
|
||||
if ( !canAddSatisfaction(satisfaction, satisfactions) ) {
|
||||
String message = getReasonForNotAddingSatisfaction(satisfaction.getCriterion().getType());
|
||||
throw new ValidationException(invalidValue(message, "resource", this, satisfaction));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1001,15 +989,12 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
}
|
||||
|
||||
public boolean satisfiesCriterions(Collection<? extends ICriterion> criterions) {
|
||||
ICriterion compositedCriterion = CriterionCompounder.buildAnd(
|
||||
criterions).getResult();
|
||||
ICriterion compositedCriterion = CriterionCompounder.buildAnd(criterions).getResult();
|
||||
return compositedCriterion.isSatisfiedBy(this);
|
||||
}
|
||||
|
||||
public boolean satisfiesCriterionsAtSomePoint(
|
||||
Collection<? extends Criterion> criterions) {
|
||||
AvailabilityTimeLine availability = AvailabilityCalculator
|
||||
.getCriterionsAvailabilityFor(criterions, this);
|
||||
public boolean satisfiesCriterionsAtSomePoint(Collection<? extends Criterion> criterions) {
|
||||
AvailabilityTimeLine availability = AvailabilityCalculator.getCriterionsAvailabilityFor(criterions, this);
|
||||
return !availability.getValidPeriods().isEmpty();
|
||||
}
|
||||
|
||||
|
|
@ -1072,8 +1057,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
*/
|
||||
for (CriterionSatisfaction i : getCriterionSatisfactions()) {
|
||||
|
||||
if (!(i.isStartDateSpecified() && i
|
||||
.isPositiveTimeInterval())) {
|
||||
if ( !(i.isStartDateSpecified() && i.isPositiveTimeInterval()) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1100,8 +1084,7 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
* If not, it does not make sense to check assignment overlapping.
|
||||
*/
|
||||
for (ResourcesCostCategoryAssignment each : getResourcesCostCategoryAssignments()) {
|
||||
if (!(each.isInitDateSpecified() && each
|
||||
.isPositiveTimeInterval())) {
|
||||
if ( !(each.isInitDateSpecified() && each.isPositiveTimeInterval()) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1190,25 +1173,25 @@ public abstract class Resource extends IntegrationEntity implements
|
|||
|
||||
@AssertTrue(message = "You have exceeded the maximum limit of resources")
|
||||
public boolean isMaxResourcesConstraint() {
|
||||
return Registry.getTransactionService()
|
||||
.runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
|
||||
return Registry.getTransactionService().runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
|
||||
@Override
|
||||
public Boolean execute() {
|
||||
Configuration configuration = Registry
|
||||
.getConfigurationDAO().getConfiguration();
|
||||
if (configuration == null) {
|
||||
Configuration configuration = Registry.getConfigurationDAO().getConfiguration();
|
||||
if ( configuration == null ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Integer maxResources = configuration.getMaxResources();
|
||||
if (maxResources != null && maxResources > 0) {
|
||||
List<Resource> resources = Registry
|
||||
.getResourceDAO().findAll();
|
||||
|
||||
if ( maxResources != null && maxResources > 0 ) {
|
||||
List<Resource> resources = Registry.getResourceDAO().findAll();
|
||||
int resourcesNumber = resources.size();
|
||||
if (isNewObject()) {
|
||||
|
||||
if ( isNewObject() ) {
|
||||
resourcesNumber++;
|
||||
}
|
||||
if (resourcesNumber > maxResources) {
|
||||
|
||||
if ( resourcesNumber > maxResources ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ import org.apache.commons.lang.Validate;
|
|||
* Implementation of {@link ITreeParentNode} that mutates a list <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public abstract class TreeNodeOnList<T extends ITreeNode<T>> implements
|
||||
ITreeParentNode<T> {
|
||||
public abstract class TreeNodeOnList<T extends ITreeNode<T>> implements ITreeParentNode<T> {
|
||||
|
||||
private final List<T> children;
|
||||
|
||||
|
|
@ -73,7 +72,7 @@ public abstract class TreeNodeOnList<T extends ITreeNode<T>> implements
|
|||
@Override
|
||||
public void down(T existentChild) {
|
||||
int position = children.indexOf(existentChild);
|
||||
if (position < children.size() - 1) {
|
||||
if ( position < children.size() - 1 ) {
|
||||
children.remove(position);
|
||||
children.add(position + 1, existentChild);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,11 +73,9 @@ public class EffortDuration implements Comparable<EffortDuration> {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern lenientEffortDurationSpecification = Pattern
|
||||
.compile("(\\d+)(\\s*:\\s*\\d+\\s*)*");
|
||||
private static final Pattern lenientEffortDurationSpecification = Pattern.compile("(\\d+)(\\s*:\\s*\\d+\\s*)*");
|
||||
|
||||
private static final Pattern contiguousDigitsPattern = Pattern
|
||||
.compile("\\d+");
|
||||
private static final Pattern contiguousDigitsPattern = Pattern.compile("\\d+");
|
||||
|
||||
/**
|
||||
* If an {@link EffortDuration} can't be parsed <code>null</code> is
|
||||
|
|
@ -379,11 +377,9 @@ public class EffortDuration implements Comparable<EffortDuration> {
|
|||
return EffortDuration.seconds(total.seconds / items);
|
||||
}
|
||||
|
||||
private static int roundHalfUpToHours(
|
||||
EnumMap<Granularity, Integer> components) {
|
||||
private static int roundHalfUpToHours(EnumMap<Granularity, Integer> components) {
|
||||
int seconds = components.get(Granularity.SECONDS);
|
||||
int minutes = components.get(Granularity.MINUTES)
|
||||
+ (seconds < 30 ? 0 : 1);
|
||||
int minutes = components.get(Granularity.MINUTES) + (seconds < 30 ? 0 : 1);
|
||||
int hours = components.get(Granularity.HOURS) + (minutes < 30 ? 0 : 1);
|
||||
return hours;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -377,8 +377,7 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Iterator<PartialDay> createIterator(
|
||||
final IntraDayDate start, final IterationPredicate predicate) {
|
||||
private static Iterator<PartialDay> createIterator(final IntraDayDate start, final IterationPredicate predicate) {
|
||||
|
||||
return new Iterator<IntraDayDate.PartialDay>() {
|
||||
private IntraDayDate current = start;
|
||||
|
|
@ -390,7 +389,7 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
|
|||
|
||||
@Override
|
||||
public PartialDay next() {
|
||||
if (!hasNext()) {
|
||||
if ( !hasNext() ) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
IntraDayDate start = current;
|
||||
|
|
@ -399,8 +398,7 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
|
|||
}
|
||||
|
||||
private IntraDayDate calculateNext(IntraDayDate date) {
|
||||
IntraDayDate nextDay = IntraDayDate.startOfDay(date.date
|
||||
.plusDays(1));
|
||||
IntraDayDate nextDay = IntraDayDate.startOfDay(date.date.plusDays(1));
|
||||
return predicate.limitNext(nextDay);
|
||||
}
|
||||
|
||||
|
|
@ -452,18 +450,13 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
|
|||
* @return a new {@link IntraDayDate}
|
||||
*/
|
||||
public IntraDayDate increaseBy(ResourcesPerDay resourcesPerDay, EffortDuration effort) {
|
||||
EffortDuration newEnd = this.getEffortDuration().plus(
|
||||
calculateProportionalDuration(resourcesPerDay,
|
||||
effort));
|
||||
EffortDuration newEnd = this.getEffortDuration().plus(calculateProportionalDuration(resourcesPerDay, effort));
|
||||
return IntraDayDate.create(getDate(), newEnd);
|
||||
}
|
||||
|
||||
private EffortDuration calculateProportionalDuration(
|
||||
ResourcesPerDay resourcesPerDay, EffortDuration effort) {
|
||||
private EffortDuration calculateProportionalDuration(ResourcesPerDay resourcesPerDay, EffortDuration effort) {
|
||||
int seconds = effort.getSeconds();
|
||||
BigDecimal end = new BigDecimal(seconds).divide(
|
||||
resourcesPerDay.getAmount(),
|
||||
RoundingMode.HALF_UP);
|
||||
BigDecimal end = new BigDecimal(seconds).divide(resourcesPerDay.getAmount(), RoundingMode.HALF_UP);
|
||||
return seconds(end.intValue());
|
||||
}
|
||||
|
||||
|
|
@ -478,22 +471,18 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
|
|||
* @param effort
|
||||
* @return a new {@link IntraDayDate}
|
||||
*/
|
||||
public IntraDayDate decreaseBy(ResourcesPerDay resourcesPerDay,
|
||||
EffortDuration effort) {
|
||||
EffortDuration proportionalDuration = calculateProportionalDuration(
|
||||
resourcesPerDay, effort);
|
||||
if (getEffortDuration().compareTo(proportionalDuration) > 0) {
|
||||
return IntraDayDate.create(getDate(),
|
||||
getEffortDuration().minus(proportionalDuration));
|
||||
public IntraDayDate decreaseBy(ResourcesPerDay resourcesPerDay, EffortDuration effort) {
|
||||
EffortDuration proportionalDuration = calculateProportionalDuration(resourcesPerDay, effort);
|
||||
if ( getEffortDuration().compareTo(proportionalDuration) > 0 ) {
|
||||
return IntraDayDate.create(getDate(), getEffortDuration().minus(proportionalDuration));
|
||||
} else {
|
||||
return IntraDayDate.startOfDay(getDate());
|
||||
}
|
||||
}
|
||||
|
||||
public static IntraDayDate convert(LocalDate date,
|
||||
IntraDayDate morePreciseAlternative) {
|
||||
public static IntraDayDate convert(LocalDate date, IntraDayDate morePreciseAlternative) {
|
||||
LocalDate morePreciseDate = morePreciseAlternative.getDate();
|
||||
if (morePreciseDate.equals(date)) {
|
||||
if ( morePreciseDate.equals(date) ) {
|
||||
return morePreciseAlternative;
|
||||
}
|
||||
return startOfDay(date);
|
||||
|
|
@ -512,13 +501,12 @@ public class IntraDayDate implements Comparable<IntraDayDate> {
|
|||
|
||||
EffortDuration result = EffortDuration.hours(days * 8);
|
||||
|
||||
if (!getEffortDuration().isZero()) {
|
||||
if ( !getEffortDuration().isZero()) {
|
||||
result = result.minus(EffortDuration.hours(8));
|
||||
result = result.plus(EffortDuration.hours(8).minus(
|
||||
getEffortDuration()));
|
||||
result = result.plus(EffortDuration.hours(8).minus(getEffortDuration()));
|
||||
}
|
||||
|
||||
if (!end.getEffortDuration().isZero()) {
|
||||
if ( !end.getEffortDuration().isZero() ) {
|
||||
result = result.plus(end.getEffortDuration());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,37 +38,31 @@ public class ProportionalDistributorTest {
|
|||
|
||||
@Test
|
||||
public void mustGiveTheSameDistributionForSameTotal() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
100, 200);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(100, 200);
|
||||
assertThat(distributor.distribute(300), equalToDistribution(100, 200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactDivisionsWorkOk() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
100, 100, 100);
|
||||
assertThat(distributor.distribute(600), equalToDistribution(200, 200,
|
||||
200));
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(100, 100, 100);
|
||||
assertThat(distributor.distribute(600), equalToDistribution(200, 200, 200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distributingZeroGivesZeroShares() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
100, 100, 100);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(100, 100, 100);
|
||||
assertThat(distributor.distribute(0), equalToDistribution(0, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifOneOfTheProportionsIsZeroAlwaysGivesZeros() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
100, 100, 0);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(100, 100, 0);
|
||||
assertThat(distributor.distribute(100), equalToDistribution(50, 50, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifEmptySharesProvidedItDistributesEqually() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(0,
|
||||
0, 0, 0);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(0, 0, 0, 0);
|
||||
assertThat(distributor.distribute(4), equalToDistribution(1, 1, 1, 1));
|
||||
assertThat(distributor.distribute(5), equalToDistribution(2, 1, 1, 1));
|
||||
assertThat(distributor.distribute(6), equalToDistribution(2, 2, 1, 1));
|
||||
|
|
@ -84,15 +78,13 @@ public class ProportionalDistributorTest {
|
|||
|
||||
@Test
|
||||
public void disputedPartGoesToFirstIfEqualWeight() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
10, 10, 10);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(10, 10, 10);
|
||||
assertThat(distributor.distribute(10), equalToDistribution(4, 3, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distributionIsKept() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(2,
|
||||
3, 5);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(2, 3, 5);
|
||||
assertThat(distributor.distribute(1), equalToDistribution(0, 0, 1));
|
||||
assertThat(distributor.distribute(2), equalToDistribution(0, 1, 1));
|
||||
assertThat(distributor.distribute(3), equalToDistribution(1, 1, 1));
|
||||
|
|
@ -105,8 +97,7 @@ public class ProportionalDistributorTest {
|
|||
|
||||
@Test
|
||||
public void addingOneEachTime() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(
|
||||
99, 101, 800);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(99, 101, 800);
|
||||
assertThat(distributor.distribute(1), equalToDistribution(0, 0, 1));
|
||||
assertThat(distributor.distribute(3), equalToDistribution(0, 0, 3));
|
||||
assertThat(distributor.distribute(6), equalToDistribution(0, 1, 5));
|
||||
|
|
@ -129,7 +120,7 @@ public class ProportionalDistributorTest {
|
|||
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
if (object instanceof int[]) {
|
||||
if ( object instanceof int[] ) {
|
||||
int[] arg = (int[]) object;
|
||||
return Arrays.equals(arg, distribution);
|
||||
}
|
||||
|
|
@ -138,8 +129,7 @@ public class ProportionalDistributorTest {
|
|||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("must equal "
|
||||
+ Arrays.toString(distribution));
|
||||
description.appendText("must equal " + Arrays.toString(distribution));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -151,8 +141,7 @@ public class ProportionalDistributorTest {
|
|||
|
||||
@Test
|
||||
public void notThrowDivisionByZeroExceptionAtDistributeMehtod() {
|
||||
ProportionalDistributor distributor = ProportionalDistributor
|
||||
.create(100);
|
||||
ProportionalDistributor distributor = ProportionalDistributor.create(100);
|
||||
distributor.distribute(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,9 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
|||
* @author Bob McCune
|
||||
* @version 1.0
|
||||
*/
|
||||
public class DBUnitTestExecutionListener extends
|
||||
TransactionalTestExecutionListener {
|
||||
public class DBUnitTestExecutionListener extends TransactionalTestExecutionListener {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(DBUnitTestExecutionListener.class);
|
||||
private static final Log logger = LogFactory.getLog(DBUnitTestExecutionListener.class);
|
||||
|
||||
private static final String DEFAULT_DATASOURCE_NAME = "dataSource";
|
||||
private static final String TABLE_TYPES[] = { "TABLE", "ALIAS" };
|
||||
|
|
|
|||
|
|
@ -29,10 +29,9 @@ package org.libreplan.business.test;
|
|||
*/
|
||||
public class BusinessGlobalNames {
|
||||
|
||||
public final static String BUSINESS_SPRING_CONFIG_TEST_FILE =
|
||||
"classpath:/libreplan-business-spring-config-test.xml";
|
||||
public final static String BUSINESS_SPRING_CONFIG_TEST_FILE = "classpath:/libreplan-business-spring-config-test.xml";
|
||||
|
||||
public final static String DBUNIT_CONFIG_TEST_FILE = "/dbunit-data.xml";
|
||||
|
||||
public final static String DBUNIT_CONFIG_TEST_FILE =
|
||||
"/dbunit-data.xml";
|
||||
private BusinessGlobalNames () {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,10 +52,8 @@ public class DefaultAdvanceTypesBootstrapListenerTest {
|
|||
private IAdvanceTypeDAO advanceTypeDAO;
|
||||
|
||||
private IDataBootstrap getAdvanceTypeBootstrap() {
|
||||
String simpleName = DefaultAdvanceTypesBootstrapListener.class
|
||||
.getSimpleName();
|
||||
return dataBootstraps.get(simpleName.substring(0, 1).toLowerCase()
|
||||
+ simpleName.substring(1));
|
||||
String simpleName = DefaultAdvanceTypesBootstrapListener.class.getSimpleName();
|
||||
return dataBootstraps.get(simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -57,8 +57,7 @@ public class AdvanceAssignmentDAOTest {
|
|||
private AdvanceType givenAdvanceType() {
|
||||
BigDecimal value = new BigDecimal(100);
|
||||
BigDecimal precision = BigDecimal.ONE;
|
||||
AdvanceType advanceType = AdvanceType.create("advance-type", value,
|
||||
true, precision, true, false);
|
||||
AdvanceType advanceType = AdvanceType.create("advance-type", value, true, precision, true, false);
|
||||
advanceTypeDAO.save(advanceType);
|
||||
return advanceType;
|
||||
}
|
||||
|
|
@ -66,8 +65,7 @@ public class AdvanceAssignmentDAOTest {
|
|||
@Test
|
||||
@Transactional
|
||||
public void saveValidAdvanceAssignment() {
|
||||
AdvanceAssignment advance = DirectAdvanceAssignment.create(false,
|
||||
BigDecimal.TEN);
|
||||
AdvanceAssignment advance = DirectAdvanceAssignment.create(false, BigDecimal.TEN);
|
||||
advance.setAdvanceType(givenAdvanceType());
|
||||
advanceAssignmentDAO.save(advance);
|
||||
assertTrue(advance.getId() != null);
|
||||
|
|
@ -76,8 +74,7 @@ public class AdvanceAssignmentDAOTest {
|
|||
@Test(expected = ValidationException.class)
|
||||
@Transactional
|
||||
public void saveAdvanceAssignmentWithZeroAsMaxValue() {
|
||||
AdvanceAssignment advance = DirectAdvanceAssignment.create(false,
|
||||
BigDecimal.ZERO);
|
||||
AdvanceAssignment advance = DirectAdvanceAssignment.create(false, BigDecimal.ZERO);
|
||||
advance.setAdvanceType(givenAdvanceType());
|
||||
advanceAssignmentDAO.save(advance);
|
||||
assertTrue(advance.getId() != null);
|
||||
|
|
@ -86,8 +83,7 @@ public class AdvanceAssignmentDAOTest {
|
|||
@Test(expected = ValidationException.class)
|
||||
@Transactional
|
||||
public void saveAdvanceAssignmentWithNegativeNumberAsMaxValue() {
|
||||
AdvanceAssignment advance = DirectAdvanceAssignment.create(false,
|
||||
BigDecimal.valueOf(-10));
|
||||
AdvanceAssignment advance = DirectAdvanceAssignment.create(false, BigDecimal.valueOf(-10));
|
||||
advance.setAdvanceType(givenAdvanceType());
|
||||
advanceAssignmentDAO.save(advance);
|
||||
assertTrue(advance.getId() != null);
|
||||
|
|
|
|||
|
|
@ -111,18 +111,13 @@ public class GenericResourceAllocationTest {
|
|||
private Task givenTaskWithStartAndEnd(Interval interval) {
|
||||
Task task = createNiceMock(Task.class);
|
||||
setupCriterions(task);
|
||||
IntraDayDate start = IntraDayDate.startOfDay(interval.getStart()
|
||||
.toLocalDate());
|
||||
IntraDayDate end = IntraDayDate.startOfDay(interval.getEnd()
|
||||
.toLocalDate());
|
||||
expect(task.getStartDate()).andReturn(interval.getStart().toDate())
|
||||
.anyTimes();
|
||||
IntraDayDate start = IntraDayDate.startOfDay(interval.getStart().toLocalDate());
|
||||
IntraDayDate end = IntraDayDate.startOfDay(interval.getEnd().toLocalDate());
|
||||
expect(task.getStartDate()).andReturn(interval.getStart().toDate()).anyTimes();
|
||||
expect(task.getIntraDayStartDate()).andReturn(start).anyTimes();
|
||||
expect(task.getEndDate()).andReturn(interval.getEnd().toDate())
|
||||
.anyTimes();
|
||||
expect(task.getEndDate()).andReturn(interval.getEnd().toDate()).anyTimes();
|
||||
expect(task.getIntraDayEndDate()).andReturn(end).anyTimes();
|
||||
expect(task.getFirstDayNotConsolidated()).andReturn(start)
|
||||
.anyTimes();
|
||||
expect(task.getFirstDayNotConsolidated()).andReturn(start).anyTimes();
|
||||
expect(task.getCalendar()).andReturn(baseCalendar).anyTimes();
|
||||
replay(task);
|
||||
return this.task = task;
|
||||
|
|
@ -137,8 +132,7 @@ public class GenericResourceAllocationTest {
|
|||
}
|
||||
|
||||
private void setupCriterions(Task task) {
|
||||
expect(task.getCriterions()).andReturn(givenPredefinedCriterions())
|
||||
.anyTimes();
|
||||
expect(task.getCriterions()).andReturn(givenPredefinedCriterions()).anyTimes();
|
||||
}
|
||||
|
||||
private void givenGenericResourceAllocationForTask(Task task) {
|
||||
|
|
@ -159,9 +153,7 @@ public class GenericResourceAllocationTest {
|
|||
}
|
||||
|
||||
private void setupIsSatisfiedByAll(Criterion criterion) {
|
||||
expect(
|
||||
criterion.isSatisfiedBy(isA(Resource.class),
|
||||
isA(LocalDate.class))).andReturn(true).anyTimes();
|
||||
expect(criterion.isSatisfiedBy(isA(Resource.class), isA(LocalDate.class))).andReturn(true).anyTimes();
|
||||
}
|
||||
|
||||
private void givenWorkersWithoutLoadAndWithoutCalendar() {
|
||||
|
|
@ -175,9 +167,8 @@ public class GenericResourceAllocationTest {
|
|||
|
||||
public static void mockZeroLoad(Resource... resources) {
|
||||
for (Resource each : resources) {
|
||||
expect(
|
||||
each.getAssignedDurationDiscounting(isA(Map.class),
|
||||
isA(LocalDate.class))).andReturn(zero()).anyTimes();
|
||||
expect(each.getAssignedDurationDiscounting(isA(Map.class), isA(LocalDate.class)))
|
||||
.andReturn(zero()).anyTimes();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +202,7 @@ public class GenericResourceAllocationTest {
|
|||
}
|
||||
|
||||
EffortDuration getLoad(LocalDate date) {
|
||||
if (exceptions.containsKey(date)) {
|
||||
if ( exceptions.containsKey(date) ) {
|
||||
return exceptions.get(date);
|
||||
}
|
||||
return defaultLoad;
|
||||
|
|
@ -219,37 +210,33 @@ public class GenericResourceAllocationTest {
|
|||
|
||||
}
|
||||
|
||||
private Worker createWorkerWithLoad(ResourceCalendar resourceCalendar,
|
||||
int hours) {
|
||||
return createWorkerWithLoad(resourceCalendar,
|
||||
new LoadSpec(hours(hours)));
|
||||
private Worker createWorkerWithLoad(ResourceCalendar resourceCalendar, int hours) {
|
||||
return createWorkerWithLoad(resourceCalendar, new LoadSpec(hours(hours)));
|
||||
}
|
||||
|
||||
private Worker createWorkerWithLoad(ResourceCalendar resourceCalendar,
|
||||
final LoadSpec loadSpec) {
|
||||
private Worker createWorkerWithLoad(ResourceCalendar resourceCalendar, final LoadSpec loadSpec) {
|
||||
Worker result = createNiceMock(Worker.class);
|
||||
expect(result.getCalendar()).andReturn(resourceCalendar).anyTimes();
|
||||
expect(
|
||||
result.getAssignedDurationDiscounting(isA(Map.class),
|
||||
isA(LocalDate.class))).andAnswer(
|
||||
|
||||
expect(result.getAssignedDurationDiscounting(isA(Map.class), isA(LocalDate.class))).andAnswer(
|
||||
new IAnswer<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
Object[] currentArguments = EasyMock
|
||||
.getCurrentArguments();
|
||||
Object[] currentArguments = EasyMock.getCurrentArguments();
|
||||
LocalDate date = (LocalDate) currentArguments[1];
|
||||
return loadSpec.getLoad(date);
|
||||
}
|
||||
}).anyTimes();
|
||||
expect(result.getSatisfactionsFor(isA(Criterion.class))).andReturn(
|
||||
satisfactionsForPredefinedCriterions(result)).anyTimes();
|
||||
|
||||
expect(result.getSatisfactionsFor(isA(Criterion.class)))
|
||||
.andReturn(satisfactionsForPredefinedCriterions(result)).anyTimes();
|
||||
|
||||
replay(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<CriterionSatisfaction> satisfactionsForPredefinedCriterions(
|
||||
Resource resource) {
|
||||
private List<CriterionSatisfaction> satisfactionsForPredefinedCriterions(Resource resource) {
|
||||
List<CriterionSatisfaction> result = new ArrayList<CriterionSatisfaction>();
|
||||
for (Criterion each : criterions) {
|
||||
result.add(CriterionSatisfaction.create(each, resource,
|
||||
|
|
@ -259,22 +246,18 @@ public class GenericResourceAllocationTest {
|
|||
}
|
||||
|
||||
private org.libreplan.business.resources.entities.Interval fromVeryEarlyTime() {
|
||||
return org.libreplan.business.resources.entities.Interval
|
||||
.from(new LocalDate(0, 1, 1));
|
||||
return org.libreplan.business.resources.entities.Interval.from(new LocalDate(0, 1, 1));
|
||||
}
|
||||
|
||||
private void givenCalendarsForResources(int capacity1, int capacity2,
|
||||
int capacity3) {
|
||||
givenCalendarsForResources(fromHours(capacity1), fromHours(capacity2),
|
||||
fromHours(capacity3));
|
||||
private void givenCalendarsForResources(int capacity1, int capacity2, int capacity3) {
|
||||
givenCalendarsForResources(fromHours(capacity1), fromHours(capacity2), fromHours(capacity3));
|
||||
}
|
||||
|
||||
private Capacity fromHours(int hours) {
|
||||
return Capacity.create(hours(hours)).overAssignableWithoutLimit();
|
||||
}
|
||||
|
||||
private void givenCalendarsForResources(Capacity capacity1,
|
||||
Capacity capacity2, Capacity capacity3) {
|
||||
private void givenCalendarsForResources(Capacity capacity1, Capacity capacity2, Capacity capacity3) {
|
||||
workerCalendars = new ArrayList<ResourceCalendar>();
|
||||
workerCalendars.add(createCalendar(ResourceCalendar.class, capacity1));
|
||||
workerCalendars.add(createCalendar(ResourceCalendar.class, capacity2));
|
||||
|
|
@ -282,18 +265,16 @@ public class GenericResourceAllocationTest {
|
|||
}
|
||||
|
||||
private void givenWorkersWithLoads(int hours1, int hours2, int hours3) {
|
||||
givenWorkersWithLoads(LoadSpec.withHours(hours1),
|
||||
LoadSpec.withHours(hours2), LoadSpec.withHours(hours3));
|
||||
givenWorkersWithLoads(LoadSpec.withHours(hours1), LoadSpec.withHours(hours2), LoadSpec.withHours(hours3));
|
||||
}
|
||||
|
||||
private void givenWorkersWithLoads(LoadSpec load1, LoadSpec load2,
|
||||
LoadSpec load3) {
|
||||
private void givenWorkersWithLoads(LoadSpec load1, LoadSpec load2, LoadSpec load3) {
|
||||
ResourceCalendar[] calendars;
|
||||
if (workerCalendars == null) {
|
||||
if ( workerCalendars == null ) {
|
||||
calendars = new ResourceCalendar[] { null, null, null };
|
||||
} else {
|
||||
calendars = new ResourceCalendar[] { workerCalendars.get(0),
|
||||
workerCalendars.get(1), workerCalendars.get(2) };
|
||||
calendars =
|
||||
new ResourceCalendar[] { workerCalendars.get(0), workerCalendars.get(1), workerCalendars.get(2) };
|
||||
}
|
||||
worker1 = createWorkerWithLoad(calendars[0], load1);
|
||||
worker2 = createWorkerWithLoad(calendars[1], load2);
|
||||
|
|
@ -302,54 +283,53 @@ public class GenericResourceAllocationTest {
|
|||
}
|
||||
|
||||
private void givenBaseCalendarWithoutExceptions(int hoursPerDay) {
|
||||
BaseCalendar baseCalendar = createCalendar(BaseCalendar.class, Capacity
|
||||
.create(hours(hoursPerDay)).overAssignableWithoutLimit());
|
||||
BaseCalendar baseCalendar =
|
||||
createCalendar(BaseCalendar.class, Capacity.create(hours(hoursPerDay)).overAssignableWithoutLimit());
|
||||
|
||||
this.baseCalendar = baseCalendar;
|
||||
}
|
||||
|
||||
private <T extends BaseCalendar> T createCalendar(Class<T> klass,
|
||||
final Capacity capacity) {
|
||||
private <T extends BaseCalendar> T createCalendar(Class<T> klass, final Capacity capacity) {
|
||||
return createCalendar(klass, capacity, 1);
|
||||
}
|
||||
|
||||
private <T extends BaseCalendar> T createCalendar(Class<T> klass,
|
||||
final Capacity capacity, int units) {
|
||||
private <T extends BaseCalendar> T createCalendar(Class<T> klass, final Capacity capacity, int units) {
|
||||
final Capacity capacityMultipliedByUnits = capacity.multiplyBy(units);
|
||||
BaseCalendar baseCalendar = createNiceMock(klass);
|
||||
|
||||
expect(baseCalendar.getCapacityOn(isA(PartialDay.class))).andAnswer(
|
||||
new IAnswer<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
PartialDay day = (PartialDay) getCurrentArguments()[0];
|
||||
return day.limitWorkingDay(capacityMultipliedByUnits
|
||||
.getStandardEffort());
|
||||
return day.limitWorkingDay(capacityMultipliedByUnits.getStandardEffort());
|
||||
}
|
||||
}).anyTimes();
|
||||
expect(baseCalendar.isActive(isA(LocalDate.class))).andReturn(true)
|
||||
.anyTimes();
|
||||
expect(baseCalendar.canWorkOn(isA(LocalDate.class))).andReturn(true)
|
||||
.anyTimes();
|
||||
expect(baseCalendar.getAvailability()).andReturn(
|
||||
AvailabilityTimeLine.allValid()).anyTimes();
|
||||
|
||||
expect(baseCalendar.isActive(isA(LocalDate.class))).andReturn(true).anyTimes();
|
||||
|
||||
expect(baseCalendar.canWorkOn(isA(LocalDate.class))).andReturn(true).anyTimes();
|
||||
|
||||
expect(baseCalendar.getAvailability()).andReturn(AvailabilityTimeLine.allValid()).anyTimes();
|
||||
|
||||
IAnswer<EffortDuration> durationAnswer = new IAnswer<EffortDuration>() {
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
PartialDay day = (PartialDay) getCurrentArguments()[0];
|
||||
ResourcesPerDay resourcesPerDay = (ResourcesPerDay) getCurrentArguments()[1];
|
||||
return capacityMultipliedByUnits.limitDuration(resourcesPerDay
|
||||
.asDurationGivenWorkingDayOf(day.limitWorkingDay(capacity
|
||||
.getStandardEffort())));
|
||||
return capacityMultipliedByUnits.limitDuration(
|
||||
resourcesPerDay.asDurationGivenWorkingDayOf(day.limitWorkingDay(capacity.getStandardEffort())));
|
||||
}
|
||||
};
|
||||
expect(
|
||||
baseCalendar.asDurationOn(isA(PartialDay.class),
|
||||
isA(ResourcesPerDay.class))).andAnswer(durationAnswer)
|
||||
.anyTimes();
|
||||
|
||||
expect(baseCalendar.asDurationOn(isA(PartialDay.class), isA(ResourcesPerDay.class)))
|
||||
.andAnswer(durationAnswer).anyTimes();
|
||||
|
||||
expect(baseCalendar.getCapacityWithOvertime(isA(LocalDate.class)))
|
||||
.andReturn(capacityMultipliedByUnits).anyTimes();
|
||||
|
||||
if (baseCalendar instanceof ResourceCalendar) {
|
||||
if ( baseCalendar instanceof ResourceCalendar ) {
|
||||
ResourceCalendar resourceCalendar = (ResourceCalendar) baseCalendar;
|
||||
expect(resourceCalendar.getCapacity()).andReturn(units).anyTimes();
|
||||
}
|
||||
|
|
@ -360,24 +340,21 @@ public class GenericResourceAllocationTest {
|
|||
@Test
|
||||
public void theCriterionsAreCopied() {
|
||||
givenGenericResourceAllocation();
|
||||
GenericResourceAllocation copied = (GenericResourceAllocation) genericResourceAllocation
|
||||
.copy(mockScenario());
|
||||
GenericResourceAllocation copied = (GenericResourceAllocation) genericResourceAllocation.copy(mockScenario());
|
||||
assertThat(copied.getCriterions(), equalTo(criterions));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasTheCriterionsOfTheTask() {
|
||||
givenGenericResourceAllocation();
|
||||
assertThat(genericResourceAllocation.getCriterions(),
|
||||
equalTo(criterions));
|
||||
assertThat(genericResourceAllocation.getCriterions(), equalTo(criterions));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOrderedAssignmentsReturnsEmptyListIfNotExistsWorker() {
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
givenGenericResourceAllocation();
|
||||
List<GenericDayAssignment> assignments = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assignments = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertNotNull(assignments);
|
||||
assertTrue(assignments.isEmpty());
|
||||
}
|
||||
|
|
@ -389,13 +366,10 @@ public class GenericResourceAllocationTest {
|
|||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assignments = genericResourceAllocation
|
||||
.getAssignments();
|
||||
assertThat(assignments,
|
||||
haveResourceAllocation(genericResourceAllocation));
|
||||
List<GenericDayAssignment> assignments = genericResourceAllocation.getAssignments();
|
||||
assertThat(assignments, haveResourceAllocation(genericResourceAllocation));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -403,18 +377,14 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(orderedAssignmentsFor, from(start).consecutiveDays(
|
||||
TASK_DURATION_DAYS));
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(orderedAssignmentsFor, from(start).consecutiveDays(TASK_DURATION_DAYS));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -422,8 +392,7 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
ResourcesPerDay resourcesPerDay = ResourcesPerDay.amount(1);
|
||||
|
|
@ -432,10 +401,8 @@ public class GenericResourceAllocationTest {
|
|||
.resourcesPerDayUntil(plusDays(start, 2))
|
||||
.allocate(resourcesPerDay);
|
||||
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
int hoursPerDay = resourcesPerDay.asDurationGivenWorkingDayOf(
|
||||
EffortDuration.hours(8)).getHours();
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
int hoursPerDay = resourcesPerDay.asDurationGivenWorkingDayOf(EffortDuration.hours(8)).getHours();
|
||||
assertThat(orderedAssignmentsFor, haveHours(hoursPerDay, hoursPerDay));
|
||||
}
|
||||
|
||||
|
|
@ -444,22 +411,18 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
ResourcesPerDay resourcesPerDay = ResourcesPerDay.amount(1);
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(resourcesPerDay);
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(resourcesPerDay);
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.resourcesPerDayUntil(plusDays(start, 2))
|
||||
.allocate(resourcesPerDay);
|
||||
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
int hoursPerDay = resourcesPerDay.asDurationGivenWorkingDayOf(
|
||||
EffortDuration.hours(8)).getHours();
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
int hoursPerDay = resourcesPerDay.asDurationGivenWorkingDayOf(EffortDuration.hours(8)).getHours();
|
||||
assertThat(orderedAssignmentsFor, haveHours(hoursPerDay, hoursPerDay));
|
||||
}
|
||||
|
||||
|
|
@ -475,8 +438,7 @@ public class GenericResourceAllocationTest {
|
|||
.resourcesPerDayUntil(minusDays(start, 1))
|
||||
.allocate(resourcesPerDay);
|
||||
|
||||
assertTrue(genericResourceAllocation.getOrderedAssignmentsFor(worker1)
|
||||
.isEmpty());
|
||||
assertTrue(genericResourceAllocation.getOrderedAssignmentsFor(worker1).isEmpty());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
@ -503,45 +465,38 @@ public class GenericResourceAllocationTest {
|
|||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.resourcesPerDayUntil(IntraDayDate.startOfDay(start))
|
||||
.allocate(resourcesPerDay);
|
||||
assertThat(genericResourceAllocation.getResourcesPerDay(),
|
||||
equalTo(ResourcesPerDay.amount(0)));
|
||||
assertTrue(genericResourceAllocation.getOrderedAssignmentsFor(worker1)
|
||||
.isEmpty());
|
||||
|
||||
assertThat(genericResourceAllocation.getResourcesPerDay(), equalTo(ResourcesPerDay.amount(0)));
|
||||
assertTrue(genericResourceAllocation.getOrderedAssignmentsFor(worker1).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theResourcesPerDayAreChangedWhenTheAllocationIsDone() {
|
||||
givenTaskWithStartAndEnd(toInterval(new LocalDate(2006, 10, 5), Period
|
||||
.days(2)));
|
||||
givenTaskWithStartAndEnd(toInterval(new LocalDate(2006, 10, 5), Period.days(2)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
ResourcesPerDay assignedResourcesPerDay = ResourcesPerDay.amount(5);
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
assignedResourcesPerDay);
|
||||
assertThat(genericResourceAllocation.getResourcesPerDay(),
|
||||
equalTo(assignedResourcesPerDay));
|
||||
genericResourceAllocation.forResources(workers).allocate(assignedResourcesPerDay);
|
||||
assertThat(genericResourceAllocation.getResourcesPerDay(), equalTo(assignedResourcesPerDay));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocatingSeveralResourcesPerDayHavingJustOneResourceProducesOvertime() {
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
final Integer standardHoursPerDay = SameWorkHoursEveryDay
|
||||
.getDefaultWorkingDay()
|
||||
.getCapacityOn(PartialDay.wholeDay(start)).getHours();
|
||||
|
||||
final Integer standardHoursPerDay =
|
||||
SameWorkHoursEveryDay.getDefaultWorkingDay().getCapacityOn(PartialDay.wholeDay(start)).getHours();
|
||||
|
||||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(standardHoursPerDay);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(ResourcesPerDay.amount(2));
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(2));
|
||||
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(orderedAssignmentsFor.get(0).getHours(),
|
||||
equalTo(standardHoursPerDay * 2));
|
||||
List<GenericDayAssignment> orderedAssignmentsFor = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(orderedAssignmentsFor.get(0).getHours(), equalTo(standardHoursPerDay * 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -550,16 +505,13 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 1;
|
||||
final int halfWorkingDay = 4;
|
||||
givenBaseCalendarWithoutExceptions(halfWorkingDay);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assigmments = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assigmments = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assigmments, haveHours(halfWorkingDay));
|
||||
}
|
||||
|
||||
|
|
@ -567,20 +519,18 @@ public class GenericResourceAllocationTest {
|
|||
public void ifThereisNoTaskCalendarTheWorkingHoursAreSpecifiedbyTheDefaultWorkingDay() {
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
final int TASK_DURATION_DAYS = 1;
|
||||
final Integer defaultWorkableHours = SameWorkHoursEveryDay
|
||||
.getDefaultWorkingDay()
|
||||
.getCapacityOn(PartialDay.wholeDay(start)).getHours();
|
||||
|
||||
final Integer defaultWorkableHours =
|
||||
SameWorkHoursEveryDay.getDefaultWorkingDay().getCapacityOn(PartialDay.wholeDay(start)).getHours();
|
||||
|
||||
givenBaseCalendarWithoutExceptions(defaultWorkableHours);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assigmments = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assigmments = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assigmments.get(0).getHours(), equalTo(defaultWorkableHours));
|
||||
}
|
||||
|
||||
|
|
@ -589,22 +539,19 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(3, 12, 1);
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(1, 1, 1, 1));
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours());
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker3);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation.getOrderedAssignmentsFor(worker3);
|
||||
assertThat(assignmentsWorker3, haveHours(7, 7, 7, 7));
|
||||
}
|
||||
|
||||
|
|
@ -613,29 +560,28 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start,
|
||||
Period.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(
|
||||
LoadSpec.withHours(3)
|
||||
.withException(start.plusDays(1), hours(1))
|
||||
.withException(start.plusDays(3), hours(8)),
|
||||
|
||||
LoadSpec.withHours(12).withException(start.plusDays(3), zero()),
|
||||
|
||||
LoadSpec.withHours(1)
|
||||
.withException(start.plusDays(1), hours(3))
|
||||
.withException(start.plusDays(3), hours(8)));
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(1, 7, 1));
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours(8));
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker3);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation.getOrderedAssignmentsFor(worker3);
|
||||
assertThat(assignmentsWorker3, haveHours(7, 1, 7));
|
||||
}
|
||||
|
||||
|
|
@ -644,27 +590,22 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start,
|
||||
Period.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(
|
||||
LoadSpec.withHours(0)
|
||||
.withException(start.plusDays(3), hours(4)),
|
||||
LoadSpec.withHours(0).withException(start.plusDays(3), hours(4)),
|
||||
LoadSpec.withHours(12),
|
||||
LoadSpec.withHours(1)
|
||||
.withException(start.plusDays(3), hours(0)));
|
||||
LoadSpec.withHours(1).withException(start.plusDays(3), hours(0)));
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker3);
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation.getOrderedAssignmentsFor(worker3);
|
||||
assertThat(assignmentsWorker3, haveHours(4));
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(8, 8, 8, 4));
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours());
|
||||
}
|
||||
|
||||
|
|
@ -673,28 +614,23 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start,
|
||||
Period.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
|
||||
Capacity workingDay = Capacity.create(hours(8));
|
||||
Capacity with2ExtraHours = workingDay
|
||||
.withAllowedExtraEffort(hours(2));
|
||||
givenCalendarsForResources(with2ExtraHours, with2ExtraHours,
|
||||
workingDay.overAssignableWithoutLimit());
|
||||
Capacity with2ExtraHours = workingDay.withAllowedExtraEffort(hours(2));
|
||||
givenCalendarsForResources(with2ExtraHours, with2ExtraHours, workingDay.overAssignableWithoutLimit());
|
||||
givenWorkersWithLoads(0, 0, 0);
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(4));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(4));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(10, 10, 10, 10));
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours(10, 10, 10, 10));
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker3);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation.getOrderedAssignmentsFor(worker3);
|
||||
assertThat(assignmentsWorker3, haveHours(12, 12, 12, 12));
|
||||
|
||||
}
|
||||
|
|
@ -704,50 +640,52 @@ public class GenericResourceAllocationTest {
|
|||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start,
|
||||
Period.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(0, 0, 0);
|
||||
|
||||
genericResourceAllocation.forResources(asList(worker1, worker2))
|
||||
.allocate(ResourcesPerDay.amount(2));
|
||||
genericResourceAllocation.forResources(asList(worker1, worker2)).allocate(ResourcesPerDay.amount(2));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(8, 8, 8, 8));
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours(8, 8, 8, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void virtualWorkersAreGivenMoreLoad() {
|
||||
final int TASK_DURATION_DAYS = 4;
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(8, 8, 8);
|
||||
givenVirtualWorkerWithCapacityAndLoad(Capacity.create(hours(8))
|
||||
.overAssignableWithoutLimit(), 5, hours(40));
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker3);
|
||||
final int TASK_DURATION_DAYS = 4;
|
||||
|
||||
givenBaseCalendarWithoutExceptions(8);
|
||||
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
|
||||
givenWorkersWithLoads(8, 8, 8);
|
||||
|
||||
givenVirtualWorkerWithCapacityAndLoad(Capacity.create(hours(8)).overAssignableWithoutLimit(), 5, hours(40));
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation.getOrderedAssignmentsFor(worker3);
|
||||
assertThat(assignmentsWorker3, haveHours(1, 1, 1, 1));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(1, 1, 1, 1));
|
||||
|
||||
List<GenericDayAssignment> virtualWorkerAssignments = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(workers.get(workers.size() - 1));
|
||||
|
||||
List<GenericDayAssignment> virtualWorkerAssignments =
|
||||
genericResourceAllocation.getOrderedAssignmentsFor(workers.get(workers.size() - 1));
|
||||
assertThat(virtualWorkerAssignments, haveHours(5, 5, 5, 5));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours(1, 1, 1, 1));
|
||||
}
|
||||
|
||||
|
|
@ -757,22 +695,19 @@ public class GenericResourceAllocationTest {
|
|||
givenBaseCalendarWithoutExceptions(8);
|
||||
givenCalendarsForResources(4, 4, 0);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(4, 4, 4);
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker1);
|
||||
List<GenericDayAssignment> assignmentsWorker1 = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
|
||||
assertThat(assignmentsWorker1, haveHours(4, 4, 4, 4));
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker2);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker2 = genericResourceAllocation.getOrderedAssignmentsFor(worker2);
|
||||
assertThat(assignmentsWorker2, haveHours(4, 4, 4, 4));
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation
|
||||
.getOrderedAssignmentsFor(worker3);
|
||||
|
||||
List<GenericDayAssignment> assignmentsWorker3 = genericResourceAllocation.getOrderedAssignmentsFor(worker3);
|
||||
assertThat(assignmentsWorker3, haveHours());
|
||||
}
|
||||
|
||||
|
|
@ -782,16 +717,16 @@ public class GenericResourceAllocationTest {
|
|||
givenBaseCalendarWithoutExceptions(8);
|
||||
givenCalendarsForResources(8, 8, 8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start,
|
||||
Period.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(8, 6, 2);
|
||||
IntraDayDate end = ResourceAllocation.allocating(
|
||||
Arrays.asList(ResourcesPerDayModification.create(
|
||||
|
||||
IntraDayDate end = ResourceAllocation.allocating(Arrays.asList(ResourcesPerDayModification.create(
|
||||
genericResourceAllocation,
|
||||
ResourcesPerDay.amount(new BigDecimal(1)), workers)))
|
||||
.untilAllocating(hours(12));
|
||||
ResourcesPerDay.amount(new BigDecimal(1)), workers))).untilAllocating(hours(12));
|
||||
|
||||
assertThat(end.getDate(), equalTo(start.plusDays(1)));
|
||||
|
||||
EffortDuration biggestLastAssignment = hours(4);
|
||||
assertThat(end.getEffortDuration(), equalTo(biggestLastAssignment));
|
||||
}
|
||||
|
|
@ -802,36 +737,33 @@ public class GenericResourceAllocationTest {
|
|||
givenBaseCalendarWithoutExceptions(8);
|
||||
givenCalendarsForResources(8, 8, 8);
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start,
|
||||
Period.days(TASK_DURATION_DAYS)));
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(TASK_DURATION_DAYS)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(8, 2, 6);
|
||||
IntraDayDate end = ResourceAllocation.allocating(
|
||||
Arrays.asList(ResourcesPerDayModification.create(
|
||||
genericResourceAllocation, ResourcesPerDay.amount(1),
|
||||
workers))).untilAllocating(hours(16));
|
||||
|
||||
IntraDayDate end = ResourceAllocation.allocating(Arrays.asList(ResourcesPerDayModification.create(
|
||||
genericResourceAllocation,
|
||||
ResourcesPerDay.amount(1),
|
||||
workers))).untilAllocating(hours(16));
|
||||
|
||||
assertThat(end.getDate(), equalTo(start.plusDays(2)));
|
||||
}
|
||||
|
||||
private void givenVirtualWorkerWithCapacityAndLoad(
|
||||
Capacity capacityPerDayAndUnit,
|
||||
int capacityUnits,
|
||||
EffortDuration load) {
|
||||
private void givenVirtualWorkerWithCapacityAndLoad(Capacity capacityPerDayAndUnit, int capacityUnits,
|
||||
EffortDuration load) {
|
||||
|
||||
VirtualWorker worker = createNiceMock(VirtualWorker.class);
|
||||
expect(
|
||||
worker.getAssignedDurationDiscounting(isA(Map.class),
|
||||
isA(LocalDate.class))).andReturn(load)
|
||||
.anyTimes();
|
||||
expect(worker.getCalendar()).andReturn(
|
||||
createCalendar(ResourceCalendar.class, capacityPerDayAndUnit,
|
||||
capacityUnits)).anyTimes();
|
||||
expect(worker.getAssignedDurationDiscounting(isA(Map.class), isA(LocalDate.class))).andReturn(load).anyTimes();
|
||||
|
||||
expect(worker.getCalendar())
|
||||
.andReturn(createCalendar(ResourceCalendar.class, capacityPerDayAndUnit, capacityUnits)).anyTimes();
|
||||
|
||||
replay(worker);
|
||||
workers.add(worker);
|
||||
}
|
||||
|
||||
private static Interval toInterval(LocalDate start, Period period) {
|
||||
return new Interval(start.toDateTimeAtStartOfDay(), start.plus(period)
|
||||
.toDateTimeAtStartOfDay());
|
||||
return new Interval(start.toDateTimeAtStartOfDay(), start.plus(period).toDateTimeAtStartOfDay());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -844,36 +776,32 @@ public class GenericResourceAllocationTest {
|
|||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(3, 12, 1);
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
assertThat(genericResourceAllocation.getAssignedHours(),
|
||||
equalTo(workableHoursDay * days));
|
||||
assertThat(genericResourceAllocation.getAssignedHours(), equalTo(workableHoursDay * days));
|
||||
|
||||
final int hoursOnSubinterval = 3;
|
||||
int daysSubinterval = 2;
|
||||
|
||||
genericResourceAllocation.forResources(workers)
|
||||
.onIntervalWithinTask(start, start.plusDays(daysSubinterval))
|
||||
.allocateHours(hoursOnSubinterval);
|
||||
|
||||
assertThat(genericResourceAllocation.getAssignedHours(),
|
||||
equalTo(hoursOnSubinterval + (days - daysSubinterval)
|
||||
* workableHoursDay));
|
||||
equalTo(hoursOnSubinterval + (days - daysSubinterval) * workableHoursDay));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theRelatedResourcesCanBeRetrieved() {
|
||||
givenTaskWithStartAndEnd(toInterval(new LocalDate(2006, 10, 5), Period
|
||||
.days(4)));
|
||||
givenTaskWithStartAndEnd(toInterval(new LocalDate(2006, 10, 5), Period.days(4)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
List<Resource> resourcesGiven = Arrays.<Resource> asList(worker1,
|
||||
worker2);
|
||||
genericResourceAllocation.forResources(resourcesGiven)
|
||||
.allocate(ResourcesPerDay.amount(1));
|
||||
List<Resource> resourcesGiven = Arrays.<Resource> asList(worker1, worker2);
|
||||
genericResourceAllocation.forResources(resourcesGiven).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
assertThat(asSet(genericResourceAllocation.getAssociatedResources()),
|
||||
equalTo(asSet(genericResourceAllocation
|
||||
.getAssociatedResources())));
|
||||
equalTo(asSet(genericResourceAllocation.getAssociatedResources())));
|
||||
}
|
||||
|
||||
private Set<Resource> asSet(Collection<Resource> associatedResources) {
|
||||
|
|
@ -890,18 +818,18 @@ public class GenericResourceAllocationTest {
|
|||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(3, 12, 1);
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
final int hoursOnSubinterval = 3;
|
||||
int daysSubinterval = 2;
|
||||
|
||||
genericResourceAllocation.withPreviousAssociatedResources().onIntervalWithinTask(
|
||||
start,
|
||||
start.plusDays(daysSubinterval)).allocateHours(
|
||||
hoursOnSubinterval);
|
||||
|
||||
assertThat(genericResourceAllocation.getAssignedHours(),
|
||||
equalTo(hoursOnSubinterval + (days - daysSubinterval)
|
||||
* workableHoursDay));
|
||||
equalTo(hoursOnSubinterval + (days - daysSubinterval) * workableHoursDay));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -913,8 +841,7 @@ public class GenericResourceAllocationTest {
|
|||
givenTaskWithStartAndEnd(toInterval(start, Period.days(days)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
|
||||
genericResourceAllocation.withPreviousAssociatedResources().allocate(
|
||||
ResourcesPerDay.amount(1));
|
||||
genericResourceAllocation.withPreviousAssociatedResources().allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
assertThat(genericResourceAllocation.getAssignedHours(), equalTo(0));
|
||||
}
|
||||
|
|
@ -929,16 +856,11 @@ public class GenericResourceAllocationTest {
|
|||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithLoads(8, 8, 8);
|
||||
|
||||
genericResourceAllocation.forResources(workers).allocate(
|
||||
ResourcesPerDay.amount(3));
|
||||
ResourcesPerDay original = genericResourceAllocation
|
||||
.getResourcesPerDay();
|
||||
genericResourceAllocation.forResources(workers).onIntervalWithinTask(start,
|
||||
start.plusDays(2)).allocateHours(60);
|
||||
ResourcesPerDay current = genericResourceAllocation
|
||||
.getResourcesPerDay();
|
||||
assertTrue(current.getAmount()
|
||||
.compareTo(original.getAmount()) > 0);
|
||||
genericResourceAllocation.forResources(workers).allocate(ResourcesPerDay.amount(3));
|
||||
ResourcesPerDay original = genericResourceAllocation.getResourcesPerDay();
|
||||
genericResourceAllocation.forResources(workers).onIntervalWithinTask(start, start.plusDays(2)).allocateHours(60);
|
||||
ResourcesPerDay current = genericResourceAllocation.getResourcesPerDay();
|
||||
assertTrue(current.getAmount().compareTo(original.getAmount()) > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,24 +69,19 @@ import org.libreplan.business.workingday.ResourcesPerDay;
|
|||
public class SpecificResourceAllocationTest {
|
||||
|
||||
public static IntraDayDate date(int year, int monthOfYear, int dayOfMonth) {
|
||||
return IntraDayDate.startOfDay(new LocalDate(year, monthOfYear,
|
||||
dayOfMonth));
|
||||
return IntraDayDate.startOfDay(new LocalDate(year, monthOfYear, dayOfMonth));
|
||||
}
|
||||
|
||||
public static IntraDayDate plusDays(IntraDayDate date, int days) {
|
||||
return IntraDayDate.create(date.getDate().plusDays(days),
|
||||
date.getEffortDuration());
|
||||
return IntraDayDate.create(date.getDate().plusDays(days), date.getEffortDuration());
|
||||
}
|
||||
|
||||
public static IntraDayDate minusDays(IntraDayDate date, int days) {
|
||||
return IntraDayDate.create(date.getDate().minusDays(days),
|
||||
date.getEffortDuration());
|
||||
return IntraDayDate.create(date.getDate().minusDays(days), date.getEffortDuration());
|
||||
}
|
||||
|
||||
public static IntraDayDate plusDaysAndEffort(IntraDayDate date, int days,
|
||||
EffortDuration effort) {
|
||||
return IntraDayDate.create(date.getDate().plusDays(days), date
|
||||
.getEffortDuration().plus(effort));
|
||||
public static IntraDayDate plusDaysAndEffort(IntraDayDate date, int days, EffortDuration effort) {
|
||||
return IntraDayDate.create(date.getDate().plusDays(days), date.getEffortDuration().plus(effort));
|
||||
}
|
||||
|
||||
private BaseCalendar baseCalendar;
|
||||
|
|
@ -109,92 +104,79 @@ public class SpecificResourceAllocationTest {
|
|||
expect(workerCalendar.getCapacityOn(isA(PartialDay.class)))
|
||||
.andReturn(EffortDuration.hours(hours)).anyTimes();
|
||||
IAnswer<? extends EffortDuration> asDurationAnswer = asDurationOnAnswer(hours(hours));
|
||||
expect(
|
||||
workerCalendar.asDurationOn(isA(PartialDay.class),
|
||||
isA(ResourcesPerDay.class)))
|
||||
.andAnswer(asDurationAnswer).anyTimes();
|
||||
|
||||
expect(workerCalendar.asDurationOn(isA(PartialDay.class), isA(ResourcesPerDay.class)))
|
||||
.andAnswer(asDurationAnswer).anyTimes();
|
||||
|
||||
expect(workerCalendar.getCapacityWithOvertime(isA(LocalDate.class)))
|
||||
.andReturn(
|
||||
Capacity.create(hours(hours))
|
||||
.overAssignableWithoutLimit()).anyTimes();
|
||||
expect(workerCalendar.getAvailability()).andReturn(
|
||||
AvailabilityTimeLine.allValid()).anyTimes();
|
||||
.andReturn(Capacity.create(hours(hours)).overAssignableWithoutLimit()).anyTimes();
|
||||
|
||||
expect(workerCalendar.getAvailability()).andReturn(AvailabilityTimeLine.allValid()).anyTimes();
|
||||
replay(workerCalendar);
|
||||
return workerCalendar;
|
||||
}
|
||||
|
||||
private static IAnswer<? extends EffortDuration> asDurationOnAnswer(
|
||||
final EffortDuration duration) {
|
||||
private static IAnswer<? extends EffortDuration> asDurationOnAnswer(final EffortDuration duration) {
|
||||
return new IAnswer<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
ResourcesPerDay perDay = (ResourcesPerDay) EasyMock
|
||||
.getCurrentArguments()[1];
|
||||
ResourcesPerDay perDay = (ResourcesPerDay) EasyMock.getCurrentArguments()[1];
|
||||
return perDay.asDurationGivenWorkingDayOf(duration);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void givenResourceCalendar(final Capacity defaultAnswer,
|
||||
final Map<LocalDate, Capacity> answersForDates) {
|
||||
private void givenResourceCalendar(final Capacity defaultAnswer, final Map<LocalDate, Capacity> answersForDates) {
|
||||
this.calendar = createNiceMock(ResourceCalendar.class);
|
||||
expect(this.calendar.getCapacityOn(isA(PartialDay.class)))
|
||||
.andAnswer(new IAnswer<EffortDuration>() {
|
||||
expect(this.calendar.getCapacityOn(isA(PartialDay.class))).andAnswer(new IAnswer<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
PartialDay day = (PartialDay) EasyMock
|
||||
.getCurrentArguments()[0];
|
||||
PartialDay day = (PartialDay) EasyMock.getCurrentArguments()[0];
|
||||
LocalDate date = day.getDate();
|
||||
if (answersForDates.containsKey(date)) {
|
||||
return day.limitWorkingDay(answersForDates
|
||||
.get(date).getStandardEffort());
|
||||
if ( answersForDates.containsKey(date) ) {
|
||||
return day.limitWorkingDay(answersForDates.get(date).getStandardEffort());
|
||||
}
|
||||
return day.limitWorkingDay(defaultAnswer
|
||||
.getStandardEffort());
|
||||
return day.limitWorkingDay(defaultAnswer.getStandardEffort());
|
||||
}
|
||||
}).anyTimes();
|
||||
|
||||
expect(this.calendar.getCapacityWithOvertime(isA(LocalDate.class)))
|
||||
.andAnswer(new IAnswer<Capacity>() {
|
||||
expect(this.calendar.getCapacityWithOvertime(isA(LocalDate.class))).andAnswer(new IAnswer<Capacity>() {
|
||||
|
||||
@Override
|
||||
public Capacity answer() throws Throwable {
|
||||
LocalDate date = (LocalDate) EasyMock
|
||||
.getCurrentArguments()[0];
|
||||
if (answersForDates.containsKey(date)) {
|
||||
LocalDate date = (LocalDate) EasyMock.getCurrentArguments()[0];
|
||||
if ( answersForDates.containsKey(date) ) {
|
||||
return answersForDates.get(date);
|
||||
}
|
||||
return defaultAnswer;
|
||||
}
|
||||
}).anyTimes();
|
||||
|
||||
final IAnswer<EffortDuration> effortAnswer = new IAnswer<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
PartialDay day = (PartialDay) EasyMock
|
||||
.getCurrentArguments()[0];
|
||||
ResourcesPerDay resourcesPerDay = (ResourcesPerDay) EasyMock
|
||||
.getCurrentArguments()[1];
|
||||
PartialDay day = (PartialDay) EasyMock.getCurrentArguments()[0];
|
||||
ResourcesPerDay resourcesPerDay = (ResourcesPerDay) EasyMock.getCurrentArguments()[1];
|
||||
|
||||
LocalDate date = day.getDate();
|
||||
Capacity capacity = answersForDates.containsKey(date) ? answersForDates
|
||||
.get(date) : defaultAnswer;
|
||||
Capacity capacity = answersForDates.containsKey(date) ? answersForDates.get(date) : defaultAnswer;
|
||||
|
||||
EffortDuration oneResourcePerDayWorkingDuration = day.limitWorkingDay(capacity.getStandardEffort());
|
||||
|
||||
EffortDuration amountRequestedDuration =
|
||||
resourcesPerDay.asDurationGivenWorkingDayOf(oneResourcePerDayWorkingDuration);
|
||||
|
||||
EffortDuration oneResourcePerDayWorkingDuration = day
|
||||
.limitWorkingDay(capacity.getStandardEffort());
|
||||
EffortDuration amountRequestedDuration = resourcesPerDay
|
||||
.asDurationGivenWorkingDayOf(oneResourcePerDayWorkingDuration);
|
||||
return capacity.limitDuration(amountRequestedDuration);
|
||||
}
|
||||
};
|
||||
expect(
|
||||
this.calendar.asDurationOn(isA(PartialDay.class),
|
||||
isA(ResourcesPerDay.class))).andAnswer(effortAnswer)
|
||||
.anyTimes();
|
||||
expect(this.calendar.getAvailability()).andReturn(
|
||||
AvailabilityTimeLine.allValid()).anyTimes();
|
||||
|
||||
expect(this.calendar.asDurationOn(isA(PartialDay.class), isA(ResourcesPerDay.class)))
|
||||
.andAnswer(effortAnswer).anyTimes();
|
||||
|
||||
expect(this.calendar.getAvailability()).andReturn(AvailabilityTimeLine.allValid()).anyTimes();
|
||||
replay(this.calendar);
|
||||
}
|
||||
|
||||
|
|
@ -207,18 +189,15 @@ public class SpecificResourceAllocationTest {
|
|||
private void givenTask(IntraDayDate start, IntraDayDate end) {
|
||||
task = createNiceMock(Task.class);
|
||||
expect(task.getCalendar()).andReturn(baseCalendar).anyTimes();
|
||||
expect(task.getStartDate()).andReturn(
|
||||
start.toDateTimeAtStartOfDay().toDate()).anyTimes();
|
||||
expect(task.getStartDate()).andReturn(start.toDateTimeAtStartOfDay().toDate()).anyTimes();
|
||||
expect(task.getIntraDayStartDate()).andReturn(start).anyTimes();
|
||||
expect(task.getEndDate()).andReturn(
|
||||
end.toDateTimeAtStartOfDay().toDate()).anyTimes();
|
||||
expect(task.getEndDate()).andReturn(end.toDateTimeAtStartOfDay().toDate()).anyTimes();
|
||||
expect(task.getIntraDayEndDate()).andReturn(end).anyTimes();
|
||||
expect(task.getFirstDayNotConsolidated()).andReturn(start).anyTimes();
|
||||
replay(task);
|
||||
}
|
||||
|
||||
private void givenSpecificResourceAllocation(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
private void givenSpecificResourceAllocation(IntraDayDate start, IntraDayDate end) {
|
||||
givenWorker();
|
||||
givenTask(start, end);
|
||||
specificResourceAllocation = SpecificResourceAllocation.create(task);
|
||||
|
|
|
|||
|
|
@ -86,8 +86,7 @@ public class TaskElementTest {
|
|||
private Dependency exampleDependency;
|
||||
|
||||
public TaskElementTest() {
|
||||
this.exampleDependency = Dependency.create(new Task(), new Task(),
|
||||
Type.END_START);
|
||||
this.exampleDependency = Dependency.create(new Task(), new Task(), Type.END_START);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -120,8 +119,7 @@ public class TaskElementTest {
|
|||
}
|
||||
|
||||
private static Date toStartOfDay(Date date) {
|
||||
return LocalDate.fromDateFields(date)
|
||||
.toDateTimeAtStartOfDay().toDate();
|
||||
return LocalDate.fromDateFields(date).toDateTimeAtStartOfDay().toDate();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -132,45 +130,38 @@ public class TaskElementTest {
|
|||
Type type = Type.START_END;
|
||||
Dependency.create(origin, destination, type);
|
||||
assertThat(origin.getDependenciesWithThisOrigin().size(), equalTo(1));
|
||||
assertThat(destination.getDependenciesWithThisDestination().size(),
|
||||
equalTo(1));
|
||||
assertThat(destination.getDependenciesWithThisDestination().size(), equalTo(1));
|
||||
origin.removeDependencyWithDestination(destination, type);
|
||||
assertThat(origin.getDependenciesWithThisOrigin().size(), equalTo(0));
|
||||
assertThat(destination.getDependenciesWithThisDestination().size(),
|
||||
equalTo(0));
|
||||
assertThat(destination.getDependenciesWithThisDestination().size(), equalTo(0));
|
||||
}
|
||||
|
||||
private void addDependenciesForChecking(TaskElement taskBeingTransformed,
|
||||
TaskElement sourceDependencyTask,
|
||||
TaskElement destinationDependencyTask) {
|
||||
Dependency.create(sourceDependencyTask, taskBeingTransformed,
|
||||
Type.END_START);
|
||||
Dependency.create(taskBeingTransformed, destinationDependencyTask,
|
||||
Type.END_START);
|
||||
private void addDependenciesForChecking(TaskElement taskBeingTransformed, TaskElement sourceDependencyTask,
|
||||
TaskElement destinationDependencyTask) {
|
||||
|
||||
Dependency.create(sourceDependencyTask, taskBeingTransformed, Type.END_START);
|
||||
Dependency.create(taskBeingTransformed, destinationDependencyTask, Type.END_START);
|
||||
}
|
||||
|
||||
public void detachRemovesDependenciesFromRelatedTasks() {
|
||||
Task taskToDetach = (Task) TaskTest.createValidTask();
|
||||
Task sourceDependencyTask = (Task) TaskTest.createValidTask();
|
||||
Task destinationDependencyTask = (Task) TaskTest.createValidTask();
|
||||
Task taskToDetach = TaskTest.createValidTask();
|
||||
Task sourceDependencyTask = TaskTest.createValidTask();
|
||||
Task destinationDependencyTask = TaskTest.createValidTask();
|
||||
taskToDetach.setName("prueba");
|
||||
taskToDetach.setNotes("blabla");
|
||||
taskToDetach.setStartDate(new Date());
|
||||
addDependenciesForChecking(taskToDetach, sourceDependencyTask,
|
||||
destinationDependencyTask);
|
||||
addDependenciesForChecking(taskToDetach, sourceDependencyTask, destinationDependencyTask);
|
||||
taskToDetach.detach();
|
||||
assertThat(sourceDependencyTask.getDependenciesWithThisOrigin().size(),
|
||||
equalTo(0));
|
||||
assertThat(destinationDependencyTask
|
||||
.getDependenciesWithThisDestination().size(), equalTo(0));
|
||||
assertThat(sourceDependencyTask.getDependenciesWithThisOrigin().size(), equalTo(0));
|
||||
assertThat(destinationDependencyTask.getDependenciesWithThisDestination().size(), equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void detachRemovesTaskFromParent() {
|
||||
TaskGroup parent = TaskGroupTest.createValidTaskGroup();
|
||||
Task child = (Task) TaskTest.createValidTask();
|
||||
Task anotherChild = (Task) TaskTest.createValidTask();
|
||||
Task child = TaskTest.createValidTask();
|
||||
Task anotherChild = TaskTest.createValidTask();
|
||||
parent.addTaskElement(child);
|
||||
parent.addTaskElement(anotherChild);
|
||||
child.detach();
|
||||
|
|
@ -198,15 +189,13 @@ public class TaskElementTest {
|
|||
|
||||
private TaskSource asTaskSource(OrderLine orderLine) {
|
||||
List<HoursGroup> hoursGroups = orderLine.getHoursGroups();
|
||||
if (hoursGroups.isEmpty()) {
|
||||
if ( hoursGroups.isEmpty() ) {
|
||||
hoursGroups = Collections.singletonList(createHoursGroup(100));
|
||||
}
|
||||
return TaskSource.create(mockSchedulingDataForVersion(orderLine),
|
||||
hoursGroups);
|
||||
return TaskSource.create(mockSchedulingDataForVersion(orderLine), hoursGroups);
|
||||
}
|
||||
|
||||
public static SchedulingDataForVersion mockSchedulingDataForVersion(
|
||||
OrderElement orderElement) {
|
||||
public static SchedulingDataForVersion mockSchedulingDataForVersion(OrderElement orderElement) {
|
||||
SchedulingDataForVersion result = createNiceMock(SchedulingDataForVersion.class);
|
||||
TaskSource taskSource = createNiceMock(TaskSource.class);
|
||||
expect(result.getOrderElement()).andReturn(orderElement).anyTimes();
|
||||
|
|
@ -233,8 +222,7 @@ public class TaskElementTest {
|
|||
addOrderTo(orderLine);
|
||||
TaskSource taskSource = asTaskSource(orderLine);
|
||||
Task task = Task.createTask(taskSource);
|
||||
assertThat(task.getPositionConstraint(),
|
||||
isOfType(PositionConstraintType.AS_SOON_AS_POSSIBLE));
|
||||
assertThat(task.getPositionConstraint(), isOfType(PositionConstraintType.AS_SOON_AS_POSSIBLE));
|
||||
}
|
||||
|
||||
private void addOrderTo(OrderElement orderElement) {
|
||||
|
|
@ -271,17 +259,15 @@ public class TaskElementTest {
|
|||
order.setInitDate(initDate);
|
||||
TaskSource taskSource = asTaskSource(orderLine);
|
||||
Task task = Task.createTask(taskSource);
|
||||
assertThat(task.getPositionConstraint(),
|
||||
isOfType(PositionConstraintType.AS_SOON_AS_POSSIBLE));
|
||||
assertThat(task.getPositionConstraint(), isOfType(PositionConstraintType.AS_SOON_AS_POSSIBLE));
|
||||
}
|
||||
|
||||
private static Matcher<TaskPositionConstraint> isOfType(
|
||||
final PositionConstraintType type) {
|
||||
private static Matcher<TaskPositionConstraint> isOfType(final PositionConstraintType type) {
|
||||
return new BaseMatcher<TaskPositionConstraint>() {
|
||||
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
if (object instanceof TaskPositionConstraint) {
|
||||
if ( object instanceof TaskPositionConstraint ) {
|
||||
TaskPositionConstraint startConstraint = (TaskPositionConstraint) object;
|
||||
return startConstraint.getConstraintType() == type;
|
||||
}
|
||||
|
|
@ -290,35 +276,30 @@ public class TaskElementTest {
|
|||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("the start constraint must be of type "
|
||||
+ type);
|
||||
description.appendText("the start constraint must be of type " + type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Matcher<TaskPositionConstraint> hasValue(
|
||||
final LocalDate value) {
|
||||
private static Matcher<TaskPositionConstraint> hasValue(final LocalDate value) {
|
||||
return new BaseMatcher<TaskPositionConstraint>() {
|
||||
|
||||
@Override
|
||||
public boolean matches(Object object) {
|
||||
if (object instanceof TaskPositionConstraint) {
|
||||
if ( object instanceof TaskPositionConstraint ) {
|
||||
TaskPositionConstraint startConstraint = (TaskPositionConstraint) object;
|
||||
LocalDate constraintDate = startConstraint
|
||||
.getConstraintDate().toDateTimeAtStartOfDay()
|
||||
.toLocalDate();
|
||||
boolean bothNotNull = value != null
|
||||
&& constraintDate != null;
|
||||
return value == constraintDate || bothNotNull
|
||||
&& constraintDate.equals(value);
|
||||
boolean bothNotNull = value != null && constraintDate != null;
|
||||
return value == constraintDate || bothNotNull && constraintDate.equals(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("the start constraint must have date "
|
||||
+ value);
|
||||
description.appendText("the start constraint must have date " + value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,10 @@ public class DistributorTest {
|
|||
|
||||
@Test
|
||||
public void theEffortIsDistributedEvenly() {
|
||||
Distributor distributor = Distributor.among(Capacity.create(hours(8)),
|
||||
Capacity.create(hours(8)));
|
||||
Distributor distributor = Distributor.among(Capacity.create(hours(8)), Capacity.create(hours(8)));
|
||||
|
||||
assertThat(distributor.distribute(hours(16)),
|
||||
hasEfforts(hours(8), hours(8)));
|
||||
assertThat(distributor.distribute(hours(8)),
|
||||
hasEfforts(hours(4), hours(4)));
|
||||
assertThat(distributor.distribute(hours(16)), hasEfforts(hours(8), hours(8)));
|
||||
assertThat(distributor.distribute(hours(8)), hasEfforts(hours(4), hours(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -33,8 +30,7 @@ public class DistributorTest {
|
|||
.notOverAssignableWithoutLimit(), Capacity.create(hours(8))
|
||||
.notOverAssignableWithoutLimit());
|
||||
|
||||
assertThat(distributor.distribute(hours(18)),
|
||||
hasEfforts(hours(8), hours(8)));
|
||||
assertThat(distributor.distribute(hours(18)), hasEfforts(hours(8), hours(8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -43,13 +39,10 @@ public class DistributorTest {
|
|||
.notOverAssignableWithoutLimit(), Capacity.create(hours(8))
|
||||
.overAssignableWithoutLimit());
|
||||
|
||||
assertThat(distributor.distribute(hours(14)),
|
||||
hasEfforts(hours(7), hours(7)));
|
||||
assertThat(distributor.distribute(hours(16)),
|
||||
hasEfforts(hours(8), hours(8)));
|
||||
assertThat(distributor.distribute(hours(14)), hasEfforts(hours(7), hours(7)));
|
||||
assertThat(distributor.distribute(hours(16)), hasEfforts(hours(8), hours(8)));
|
||||
|
||||
assertThat(distributor.distribute(hours(18)),
|
||||
hasEfforts(hours(8), hours(10)));
|
||||
assertThat(distributor.distribute(hours(18)), hasEfforts(hours(8), hours(10)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -58,25 +51,19 @@ public class DistributorTest {
|
|||
.withAllowedExtraEffort(hours(2)), Capacity.create(hours(8))
|
||||
.notOverAssignableWithoutLimit());
|
||||
|
||||
assertThat(distributor.distribute(hours(16)),
|
||||
hasEfforts(hours(8), hours(8)));
|
||||
assertThat(distributor.distribute(hours(17)),
|
||||
hasEfforts(hours(9), hours(8)));
|
||||
assertThat(distributor.distribute(hours(18)),
|
||||
hasEfforts(hours(10), hours(8)));
|
||||
assertThat(distributor.distribute(hours(19)),
|
||||
hasEfforts(hours(10), hours(8)));
|
||||
assertThat(distributor.distribute(hours(16)), hasEfforts(hours(8), hours(8)));
|
||||
assertThat(distributor.distribute(hours(17)), hasEfforts(hours(9), hours(8)));
|
||||
assertThat(distributor.distribute(hours(18)), hasEfforts(hours(10), hours(8)));
|
||||
assertThat(distributor.distribute(hours(19)), hasEfforts(hours(10), hours(8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifNoCapacityItReturnsZeroHours() {
|
||||
Distributor distributor = Distributor.among(Capacity.create(hours(0))
|
||||
.notOverAssignableWithoutLimit());
|
||||
Distributor distributor = Distributor.among(Capacity.create(hours(0)).notOverAssignableWithoutLimit());
|
||||
assertThat(distributor.distribute(hours(4)), hasEfforts(hours(0)));
|
||||
}
|
||||
|
||||
private Matcher<List<EffortDuration>> hasEfforts(
|
||||
final EffortDuration... efforts) {
|
||||
private Matcher<List<EffortDuration>> hasEfforts(final EffortDuration... efforts) {
|
||||
return new BaseMatcher<List<EffortDuration>>() {
|
||||
|
||||
@Override
|
||||
|
|
@ -85,10 +72,10 @@ public class DistributorTest {
|
|||
}
|
||||
|
||||
private EffortDuration[] toArray(Object value) {
|
||||
if (value instanceof EffortDuration[]) {
|
||||
if ( value instanceof EffortDuration[] ) {
|
||||
return (EffortDuration[]) value;
|
||||
}
|
||||
if (value instanceof List) {
|
||||
if ( value instanceof List ) {
|
||||
List<?> list = (List<?>) value;
|
||||
return list.toArray(new EffortDuration[0]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ package org.libreplan.web;
|
|||
*/
|
||||
public class WebappGlobalNames {
|
||||
|
||||
private WebappGlobalNames() {
|
||||
}
|
||||
private WebappGlobalNames() {}
|
||||
|
||||
public final static String WEBAPP_SPRING_CONFIG_FILE = "classpath:/libreplan-webapp-spring-config.xml";
|
||||
|
||||
public final static String WEBAPP_SPRING_SECURITY_CONFIG_FILE = "classpath:/libreplan-webapp-spring-security-config.xml";
|
||||
public final static String WEBAPP_SPRING_SECURITY_CONFIG_FILE =
|
||||
"classpath:/libreplan-webapp-spring-security-config.xml";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@Qualifier("main")
|
||||
@OnConcurrentModification(goToPage = "/calendars/calendars.zul")
|
||||
public class BaseCalendarModel extends IntegrationEntityModel implements
|
||||
IBaseCalendarModel {
|
||||
public class BaseCalendarModel extends IntegrationEntityModel implements IBaseCalendarModel {
|
||||
|
||||
/**
|
||||
* Conversation state
|
||||
|
|
|
|||
|
|
@ -159,8 +159,7 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
|
||||
CalendarExceptionType getCalendarExceptionType(LocalDate date);
|
||||
|
||||
void updateException(CalendarExceptionType type, LocalDate startDate,
|
||||
LocalDate endDate, Capacity capacity);
|
||||
void updateException(CalendarExceptionType type, LocalDate startDate, LocalDate endDate, Capacity capacity);
|
||||
|
||||
void removeCalendarData(CalendarData calendarData);
|
||||
|
||||
|
|
@ -176,11 +175,9 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
|
||||
void createCalendarAvailability();
|
||||
|
||||
void setStartDate(CalendarAvailability calendarAvailability,
|
||||
LocalDate startDate) throws IllegalArgumentException;
|
||||
void setStartDate(CalendarAvailability calendarAvailability, LocalDate startDate) throws IllegalArgumentException;
|
||||
|
||||
void setEndDate(CalendarAvailability calendarAvailability, LocalDate endDate)
|
||||
throws IllegalArgumentException;
|
||||
void setEndDate(CalendarAvailability calendarAvailability, LocalDate endDate) throws IllegalArgumentException;
|
||||
|
||||
/*
|
||||
* Final conversation steps
|
||||
|
|
@ -212,11 +209,9 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
|
||||
Date getCurrentExpiringDate();
|
||||
|
||||
void checkChangeExpiringDate(CalendarData version, Date date)
|
||||
throws ValidationException;
|
||||
void checkChangeExpiringDate(CalendarData version, Date date) throws ValidationException;
|
||||
|
||||
void checkAndChangeStartDate(CalendarData version, Date date)
|
||||
throws ValidationException;
|
||||
void checkAndChangeStartDate(CalendarData version, Date date) throws ValidationException;
|
||||
|
||||
boolean isOwnExceptionDay();
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@Qualifier("subclass")
|
||||
public class ResourceCalendarModel extends BaseCalendarModel implements
|
||||
IBaseCalendarModel {
|
||||
public class ResourceCalendarModel extends BaseCalendarModel implements IBaseCalendarModel {
|
||||
|
||||
@Override
|
||||
public void initCreate() {
|
||||
|
|
|
|||
|
|
@ -255,14 +255,12 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
|
||||
public void removeEntitySequences(final List<EntitySequence> sequences) {
|
||||
// first one is necessary to remove the deleted sequences.
|
||||
List<EntitySequence> toRemove = entitySequenceDAO
|
||||
.findEntitySquencesNotIn(sequences);
|
||||
List<EntitySequence> toRemove = entitySequenceDAO.findEntitySquencesNotIn(sequences);
|
||||
for (final EntitySequence entitySequence : toRemove) {
|
||||
try {
|
||||
entitySequenceDAO.remove(entitySequence);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new ValidationException(
|
||||
_("Some sequences to be removed do not exist"));
|
||||
throw new ValidationException(_("Some sequences to be removed do not exist"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ValidationException(e.getMessage());
|
||||
}
|
||||
|
|
@ -273,7 +271,7 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
// it updates the sequences that are not active first
|
||||
List<EntitySequence> toSaveAfter = new ArrayList<EntitySequence>();
|
||||
for (EntitySequence entitySequence : sequences) {
|
||||
if (entitySequence.isActive()) {
|
||||
if ( entitySequence.isActive() ) {
|
||||
toSaveAfter.add(entitySequence);
|
||||
} else {
|
||||
entitySequenceDAO.save(entitySequence);
|
||||
|
|
|
|||
|
|
@ -42,29 +42,30 @@ import org.springframework.dao.OptimisticLockingFailureException;
|
|||
@Order(0)
|
||||
public class ConcurrentModificationHandling {
|
||||
|
||||
public static <T> T addHandling(final String goToPage,
|
||||
Class<T> interfaceKlass, T toBeWraped) {
|
||||
public static <T> T addHandling(final String goToPage, Class<T> interfaceKlass, T toBeWraped) {
|
||||
Class<?>[] classesToProxy = { interfaceKlass };
|
||||
Object result = Proxy.newProxyInstance(interfaceKlass.getClassLoader(),
|
||||
classesToProxy, handler(toBeWraped, goToPage));
|
||||
|
||||
Object result =
|
||||
Proxy.newProxyInstance(interfaceKlass.getClassLoader(), classesToProxy, handler(toBeWraped, goToPage));
|
||||
|
||||
return interfaceKlass.cast(result);
|
||||
}
|
||||
|
||||
private static InvocationHandler handler(final Object toBeWraped,
|
||||
final String goToPage) {
|
||||
private static InvocationHandler handler(final Object toBeWraped, final String goToPage) {
|
||||
return new InvocationHandler() {
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method,
|
||||
Object[] args) throws Throwable {
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
try {
|
||||
return method.invoke(toBeWraped, args);
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof OptimisticLockingFailureException) {
|
||||
OptimisticLockingFailureException optimisticLockingFailureException = (OptimisticLockingFailureException) cause;
|
||||
ConcurrentModificationController.showException(
|
||||
optimisticLockingFailureException, goToPage);
|
||||
if ( cause instanceof OptimisticLockingFailureException ) {
|
||||
|
||||
OptimisticLockingFailureException optimisticLockingFailureException =
|
||||
(OptimisticLockingFailureException) cause;
|
||||
|
||||
ConcurrentModificationController.showException(optimisticLockingFailureException, goToPage);
|
||||
}
|
||||
throw cause;
|
||||
}
|
||||
|
|
@ -77,8 +78,7 @@ public class ConcurrentModificationHandling {
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
@Pointcut("@within(onConcurrentModification))")
|
||||
private void methodWithinConcurrentModificationMarkedType(
|
||||
OnConcurrentModification onConcurrentModification) {
|
||||
private void methodWithinConcurrentModificationMarkedType(OnConcurrentModification onConcurrentModification) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,15 +92,14 @@ public class ConcurrentModificationHandling {
|
|||
* the annotation applied to object's type
|
||||
* @return the object that would be originally returned
|
||||
*/
|
||||
@Around("methodWithinConcurrentModificationMarkedType(onConcurrentModification)"
|
||||
+ " && execution(public * * (..))")
|
||||
@Around("methodWithinConcurrentModificationMarkedType(onConcurrentModification)" + " && execution(public * * (..))")
|
||||
public Object whenConcurrentModification(ProceedingJoinPoint jointPoint,
|
||||
OnConcurrentModification onConcurrentModification) throws Throwable {
|
||||
OnConcurrentModification onConcurrentModification) throws Throwable {
|
||||
|
||||
try {
|
||||
return jointPoint.proceed(jointPoint.getArgs());
|
||||
} catch (OptimisticLockingFailureException e) {
|
||||
ConcurrentModificationController.showException(e,
|
||||
onConcurrentModification.goToPage());
|
||||
ConcurrentModificationController.showException(e, onConcurrentModification.goToPage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
/**
|
||||
* @author Diego Pino García <ltilve@igalia.com>
|
||||
*
|
||||
* Model for UI operations related to CostStatus in Dashboard view
|
||||
* Model for UI operations related to CostStatus in Dashboard view
|
||||
*
|
||||
* FIXME: This Model contains several operations for calculating 'Earned
|
||||
* Value' measures related with cost. The code for calculating the basic
|
||||
* measures: BCWP, ACWP and BCWS is copied from
|
||||
* {@link OrderPlanningModel}. At this moment this code cannot be reused
|
||||
* as it's coupled with the logic for displaying the 'Earned Value'
|
||||
* chart. We may consider to refactor this code in the future.
|
||||
* FIXME: This Model contains several operations for calculating 'Earned
|
||||
* Value' measures related with cost. The code for calculating the basic
|
||||
* measures: BCWP, ACWP and BCWS is copied from
|
||||
* {@link OrderPlanningModel}. At this moment this code cannot be reused
|
||||
* as it's coupled with the logic for displaying the 'Earned Value'
|
||||
* chart. We may consider to refactor this code in the future.
|
||||
*/
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
|
|
@ -63,28 +63,24 @@ public class CostStatusModel implements ICostStatusModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCostPerformanceIndex(BigDecimal budgetedCost,
|
||||
BigDecimal actualCost) {
|
||||
public BigDecimal getCostPerformanceIndex(BigDecimal budgetedCost, BigDecimal actualCost) {
|
||||
return earnedValueCalculator.getCostPerformanceIndex(budgetedCost,
|
||||
actualCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getCostVariance(BigDecimal budgetedCost,
|
||||
BigDecimal actualCost) {
|
||||
public BigDecimal getCostVariance(BigDecimal budgetedCost, BigDecimal actualCost) {
|
||||
return earnedValueCalculator.getCostVariance(budgetedCost, actualCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getEstimateAtCompletion(BigDecimal budgetAtCompletion,
|
||||
BigDecimal costPerformanceIndex) {
|
||||
public BigDecimal getEstimateAtCompletion(BigDecimal budgetAtCompletion, BigDecimal costPerformanceIndex) {
|
||||
return earnedValueCalculator.getEstimateAtCompletion(
|
||||
budgetAtCompletion, costPerformanceIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getVarianceAtCompletion(BigDecimal budgetAtCompletion,
|
||||
BigDecimal estimateAtCompletion) {
|
||||
public BigDecimal getVarianceAtCompletion(BigDecimal budgetAtCompletion, BigDecimal estimateAtCompletion) {
|
||||
return budgetAtCompletion.subtract(estimateAtCompletion);
|
||||
}
|
||||
|
||||
|
|
@ -100,15 +96,12 @@ public class CostStatusModel implements ICostStatusModel {
|
|||
|
||||
@Override
|
||||
public BigDecimal getBudgetedCostWorkPerformedAt(LocalDate date) {
|
||||
return earnedValueCalculator
|
||||
.getBudgetedCostWorkPerformedAt(order, date);
|
||||
return earnedValueCalculator.getBudgetedCostWorkPerformedAt(order, date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getEstimateToComplete(BigDecimal estimateAtCompletion,
|
||||
BigDecimal actualCost) {
|
||||
return earnedValueCalculator.getEstimateToComplete(
|
||||
estimateAtCompletion, actualCost);
|
||||
public BigDecimal getEstimateToComplete(BigDecimal estimateAtCompletion, BigDecimal actualCost) {
|
||||
return earnedValueCalculator.getEstimateToComplete(estimateAtCompletion, actualCost);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -278,14 +278,15 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
public void initEdit(Order orderToEdit, Desktop desktop) {
|
||||
Validate.notNull(orderToEdit);
|
||||
loadNeededDataForConversation();
|
||||
this.planningState = planningStateCreator.retrieveOrCreate(desktop,
|
||||
orderToEdit, new IActionsOnRetrieval() {
|
||||
|
||||
this.planningState = planningStateCreator.retrieveOrCreate(desktop, orderToEdit, new IActionsOnRetrieval() {
|
||||
|
||||
@Override
|
||||
public void onRetrieval(PlanningState planningState) {
|
||||
planningState.reattach();
|
||||
}
|
||||
});
|
||||
|
||||
Order order = this.planningState.getOrder();
|
||||
this.orderElementTreeModel = new OrderElementTreeModel(order);
|
||||
forceLoadAdvanceAssignmentsAndMeasurements(order);
|
||||
|
|
@ -301,7 +302,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
}
|
||||
|
||||
private void forceLoadEndDateCommunicationToCustomer(Order order) {
|
||||
if (order != null) {
|
||||
if ( order != null ) {
|
||||
order.getEndDateCommunicationToCustomer().size();
|
||||
}
|
||||
}
|
||||
|
|
@ -413,8 +414,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
}
|
||||
|
||||
private void initializeOrder() {
|
||||
this.orderElementTreeModel = new OrderElementTreeModel(
|
||||
planningState.getOrder());
|
||||
this.orderElementTreeModel = new OrderElementTreeModel(planningState.getOrder());
|
||||
}
|
||||
|
||||
private void initializeCode() {
|
||||
|
|
@ -430,18 +430,17 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
@Transactional(readOnly = true)
|
||||
public void prepareCreationFrom(OrderTemplate template, Desktop desktop) {
|
||||
loadNeededDataForConversation();
|
||||
Order newOrder = createOrderFrom((OrderTemplate) templateDAO
|
||||
.findExistingEntity(template.getId()));
|
||||
Order newOrder = createOrderFrom((OrderTemplate) templateDAO.findExistingEntity(template.getId()));
|
||||
|
||||
newOrder.setCode(getOrder().getCode());
|
||||
newOrder.setCodeAutogenerated(true);
|
||||
|
||||
newOrder.setName(getOrder().getName());
|
||||
newOrder.setCustomer(((Order) getOrder()).getCustomer());
|
||||
newOrder.setCustomer(getOrder().getCustomer());
|
||||
newOrder.setCalendar(getCalendar());
|
||||
|
||||
newOrder.setInitDate(getOrder().getInitDate());
|
||||
if (getOrder().getDeadline() != null) {
|
||||
if ( getOrder().getDeadline() != null ) {
|
||||
newOrder.setDeadline(getOrder().getDeadline());
|
||||
}
|
||||
|
||||
|
|
@ -454,20 +453,17 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
return template.createOrder(scenarioManager.getCurrent());
|
||||
}
|
||||
|
||||
private OrderElement createOrderElementFrom(OrderLineGroup parent,
|
||||
OrderElementTemplate template) {
|
||||
private OrderElement createOrderElementFrom(OrderLineGroup parent, OrderElementTemplate template) {
|
||||
Validate.notNull(parent);
|
||||
return template.createElement(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public OrderElement createFrom(OrderLineGroup parent,
|
||||
OrderElementTemplate template) {
|
||||
public OrderElement createFrom(OrderLineGroup parent, OrderElementTemplate template) {
|
||||
reattachNeededDataForConversation();
|
||||
OrderElement result = createOrderElementFrom(parent, templateDAO
|
||||
.findExistingEntity(template.getId()));
|
||||
if (isCodeAutogenerated()) {
|
||||
OrderElement result = createOrderElementFrom(parent, templateDAO.findExistingEntity(template.getId()));
|
||||
if ( isCodeAutogenerated() ) {
|
||||
setAllCodeToNull(result);
|
||||
}
|
||||
forceLoadAdvanceAssignmentsAndMeasurements(result);
|
||||
|
|
@ -496,7 +492,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
reattachCriterions();
|
||||
}
|
||||
};
|
||||
if (showSaveMessage) {
|
||||
if ( showSaveMessage ) {
|
||||
this.planningState.getSaveCommand().save(beforeSaveActions);
|
||||
} else {
|
||||
this.planningState.getSaveCommand().save(beforeSaveActions, null);
|
||||
|
|
@ -504,7 +500,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
}
|
||||
|
||||
private void reattachCalendar() {
|
||||
if (planningState.getOrder().getCalendar() == null) {
|
||||
if ( planningState.getOrder().getCalendar() == null ) {
|
||||
return;
|
||||
}
|
||||
BaseCalendar calendar = planningState.getOrder().getCalendar();
|
||||
|
|
@ -529,7 +525,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
public void remove(Order detachedOrder) {
|
||||
Order order = orderDAO.findExistingEntity(detachedOrder.getId());
|
||||
removeVersions(order);
|
||||
if (order.hasNoVersions()) {
|
||||
if ( order.hasNoVersions() ) {
|
||||
removeOrderFromDB(order);
|
||||
}
|
||||
}
|
||||
|
|
@ -537,22 +533,22 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
private void removeVersions(Order order) {
|
||||
Map<Long, OrderVersion> versionsRemovedById = new HashMap<Long, OrderVersion>();
|
||||
List<Scenario> currentAndDerived = currentAndDerivedScenarios();
|
||||
|
||||
for (Scenario each : currentAndDerived) {
|
||||
OrderVersion versionRemoved = order.disassociateFrom(each);
|
||||
if (versionRemoved != null) {
|
||||
if ( versionRemoved != null ) {
|
||||
versionsRemovedById.put(versionRemoved.getId(), versionRemoved);
|
||||
}
|
||||
}
|
||||
for (OrderVersion each : versionsRemovedById.values()) {
|
||||
if (!order.isVersionUsed(each)) {
|
||||
if ( !order.isVersionUsed(each) ) {
|
||||
removeOrderVersionAt(each, currentAndDerived);
|
||||
removeOrderVersionFromDB(each);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeOrderVersionAt(OrderVersion orderVersion,
|
||||
Collection<? extends Scenario> currentAndDerived) {
|
||||
private void removeOrderVersionAt(OrderVersion orderVersion, Collection<? extends Scenario> currentAndDerived) {
|
||||
for (Scenario each : currentAndDerived) {
|
||||
each.removeVersion(orderVersion);
|
||||
}
|
||||
|
|
@ -562,8 +558,7 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
List<Scenario> scenariosToBeDisassociatedFrom = new ArrayList<Scenario>();
|
||||
Scenario currentScenario = scenarioManager.getCurrent();
|
||||
scenariosToBeDisassociatedFrom.add(currentScenario);
|
||||
scenariosToBeDisassociatedFrom.addAll(scenarioDAO
|
||||
.getDerivedScenarios(currentScenario));
|
||||
scenariosToBeDisassociatedFrom.addAll(scenarioDAO.getDerivedScenarios(currentScenario));
|
||||
return scenariosToBeDisassociatedFrom;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ import org.zkoss.zul.Window;
|
|||
|
||||
public class ProjectDetailsController extends GenericForwardComposer {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(AdvanceConsolidationController.class);
|
||||
private static final Log LOG = LogFactory.getLog(AdvanceConsolidationController.class);
|
||||
|
||||
private OrderCRUDController orderController;
|
||||
|
||||
|
|
@ -96,8 +95,8 @@ public class ProjectDetailsController extends GenericForwardComposer {
|
|||
private OrderTemplate template;
|
||||
|
||||
public ProjectDetailsController() {
|
||||
Window window = (Window) Executions.createComponents(
|
||||
"/orders/_projectDetails.zul", null,
|
||||
|
||||
Window window = (Window) Executions.createComponents("/orders/_projectDetails.zul", null,
|
||||
new HashMap<String, String>());
|
||||
try {
|
||||
doAfterCompose(window);
|
||||
|
|
@ -113,13 +112,11 @@ public class ProjectDetailsController extends GenericForwardComposer {
|
|||
window.setVariable("projectController", this, true);
|
||||
}
|
||||
|
||||
public void showWindow(OrderCRUDController orderController,
|
||||
MultipleTabsPlannerController tabs) {
|
||||
public void showWindow(OrderCRUDController orderController, MultipleTabsPlannerController tabs) {
|
||||
this.tabs = tabs;
|
||||
this.orderController = orderController;
|
||||
this.defaultCalendar = orderController.getOrder().getCalendar();
|
||||
this.isCodeAutogeneratedInit = orderController.getOrder()
|
||||
.isCodeAutogenerated();
|
||||
this.isCodeAutogeneratedInit = orderController.getOrder().isCodeAutogenerated();
|
||||
try {
|
||||
Util.reloadBindings(window);
|
||||
Util.createBindingsFor(gridProjectDetails);
|
||||
|
|
@ -138,18 +135,17 @@ public class ProjectDetailsController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public void accept() {
|
||||
if (validate()) {
|
||||
if ( validate() ) {
|
||||
Desktop desktop = window.getDesktop();
|
||||
IOrderModel orderModel = orderController.getOrderModel();
|
||||
if (bdProjectTemplate.getSelectedElement() != null) {
|
||||
OrderTemplate template = (OrderTemplate) bdProjectTemplate
|
||||
.getSelectedElement();
|
||||
if ( bdProjectTemplate.getSelectedElement() != null ) {
|
||||
OrderTemplate template = (OrderTemplate) bdProjectTemplate.getSelectedElement();
|
||||
orderModel.prepareCreationFrom(template, desktop);
|
||||
} else {
|
||||
orderModel.initEdit(orderController.getOrder(), desktop);
|
||||
}
|
||||
orderModel.save();
|
||||
if (tabs != null) {
|
||||
if ( tabs != null ) {
|
||||
tabs.goToOrderDetails(orderController.getOrder());
|
||||
}
|
||||
orderController.editNewCreatedOrder(window);
|
||||
|
|
@ -158,11 +154,11 @@ public class ProjectDetailsController extends GenericForwardComposer {
|
|||
|
||||
private boolean validate() {
|
||||
ConstraintChecker.isValid(window);
|
||||
if (initDate.getValue() == null) {
|
||||
if ( initDate.getValue() == null ) {
|
||||
showWrongValue();
|
||||
return false;
|
||||
}
|
||||
if (orderDAO.existsByNameAnotherTransaction(txtName.getValue())) {
|
||||
if ( orderDAO.existsByNameAnotherTransaction(txtName.getValue()) ) {
|
||||
showWrongName();
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,9 @@ import org.libreplan.business.workingday.EffortDuration.IEffortFrom;
|
|||
|
||||
public class AllocationRowsHandler {
|
||||
|
||||
public static AllocationRowsHandler create(Task task,
|
||||
List<AllocationRow> initialAllocations, IWorkerFinder workerFinder) {
|
||||
public static AllocationRowsHandler create(Task task, List<AllocationRow> initialAllocations,
|
||||
IWorkerFinder workerFinder) {
|
||||
|
||||
return new AllocationRowsHandler(task, initialAllocations, workerFinder);
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +249,7 @@ public class AllocationRowsHandler {
|
|||
|
||||
public Flagged<AllocationResult, Warnings> doAllocation() {
|
||||
checkInvalidValues();
|
||||
if (!currentRows.isEmpty()) {
|
||||
if ( !currentRows.isEmpty() ) {
|
||||
List<? extends AllocationModification> modificationsDone;
|
||||
modificationsDone = doSuitableAllocation();
|
||||
|
||||
|
|
@ -256,20 +257,20 @@ public class AllocationRowsHandler {
|
|||
|
||||
createDerived();
|
||||
AllocationResult result = createResult();
|
||||
if (AllocationModification.allFullfiled(AllocationModification
|
||||
.ofType(EffortModification.class, modificationsDone))) {
|
||||
|
||||
if ( AllocationModification.allFullfiled(AllocationModification
|
||||
.ofType(EffortModification.class, modificationsDone)) ) {
|
||||
|
||||
return Flagged.justValue(result);
|
||||
} else {
|
||||
return Flagged.withFlags(result,
|
||||
Warnings.SOME_GOALS_NOT_FULFILLED);
|
||||
return Flagged.withFlags(result, Warnings.SOME_GOALS_NOT_FULFILLED);
|
||||
}
|
||||
}
|
||||
return Flagged.justValue(createResult());
|
||||
}
|
||||
|
||||
private AllocationResult createResult() {
|
||||
return AllocationResult.create(task,
|
||||
calculatedValue, currentRows, getWorkableDaysIfApplyable());
|
||||
return AllocationResult.create(task, calculatedValue, currentRows, getWorkableDaysIfApplyable());
|
||||
}
|
||||
|
||||
private List<? extends AllocationModification> doSuitableAllocation() {
|
||||
|
|
@ -278,30 +279,34 @@ public class AllocationRowsHandler {
|
|||
case NUMBER_OF_HOURS:
|
||||
allocationModifications = calculateNumberOfHoursAllocation();
|
||||
break;
|
||||
|
||||
case END_DATE:
|
||||
allocationModifications = calculateEndDateOrStartDateAllocation();
|
||||
break;
|
||||
|
||||
case RESOURCES_PER_DAY:
|
||||
allocationModifications = calculateResourcesPerDayAllocation();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("cant handle: " + calculatedValue);
|
||||
}
|
||||
|
||||
AssignmentFunction.applyAssignmentFunctionsIfAny(AllocationModification
|
||||
.getBeingModified(allocationModifications));
|
||||
AssignmentFunction
|
||||
.applyAssignmentFunctionsIfAny(AllocationModification.getBeingModified(allocationModifications));
|
||||
|
||||
return allocationModifications;
|
||||
}
|
||||
|
||||
private List<ResourcesPerDayModification> calculateNumberOfHoursAllocation() {
|
||||
List<ResourcesPerDayModification> allocations = AllocationRow
|
||||
.createAndAssociate(task, currentRows, requestedToRemove);
|
||||
if (isForwardsAllocation()) {
|
||||
ResourceAllocation.allocating(allocations).allocateUntil(
|
||||
formBinder.getAllocationEnd());
|
||||
|
||||
List<ResourcesPerDayModification> allocations =
|
||||
AllocationRow.createAndAssociate(task, currentRows, requestedToRemove);
|
||||
|
||||
if ( isForwardsAllocation() ) {
|
||||
ResourceAllocation.allocating(allocations).allocateUntil(formBinder.getAllocationEnd());
|
||||
} else {
|
||||
ResourceAllocation.allocating(allocations).allocateFromEndUntil(
|
||||
formBinder.getAllocationStart());
|
||||
ResourceAllocation.allocating(allocations).allocateFromEndUntil(formBinder.getAllocationStart());
|
||||
}
|
||||
return allocations;
|
||||
}
|
||||
|
|
@ -337,48 +342,45 @@ public class AllocationRowsHandler {
|
|||
}
|
||||
|
||||
private List<EffortModification> calculateResourcesPerDayAllocation() {
|
||||
List<EffortModification> hours = AllocationRow
|
||||
.createHoursModificationsAndAssociate(task, currentRows,
|
||||
requestedToRemove);
|
||||
if (isForwardsAllocation()) {
|
||||
ResourceAllocation.allocatingHours(hours).allocateUntil(
|
||||
formBinder.getAllocationEnd());
|
||||
List<EffortModification> hours =
|
||||
AllocationRow.createHoursModificationsAndAssociate(task, currentRows, requestedToRemove);
|
||||
|
||||
if ( isForwardsAllocation() ) {
|
||||
ResourceAllocation.allocatingHours(hours).allocateUntil(formBinder.getAllocationEnd());
|
||||
} else {
|
||||
ResourceAllocation.allocatingHours(hours).allocateFromEndUntil(
|
||||
formBinder.getAllocationStart());
|
||||
ResourceAllocation.allocatingHours(hours).allocateFromEndUntil(formBinder.getAllocationStart());
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
private Integer getWorkableDaysIfApplyable() {
|
||||
switch (calculatedValue) {
|
||||
|
||||
case NUMBER_OF_HOURS:
|
||||
|
||||
case RESOURCES_PER_DAY:
|
||||
return formBinder.getWorkableDays();
|
||||
|
||||
case END_DATE:
|
||||
return null;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("unexpected calculatedValue: "
|
||||
+ calculatedValue);
|
||||
throw new RuntimeException("unexpected calculatedValue: " + calculatedValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDerived() {
|
||||
List<ResourceAllocation<?>> lastFrom = AllocationRow
|
||||
.getBeingModified(currentRows);
|
||||
List<ResourceAllocation<?>> lastFrom = AllocationRow.getBeingModified(currentRows);
|
||||
for (ResourceAllocation<?> each : lastFrom) {
|
||||
each.createDerived(workersFinder);
|
||||
}
|
||||
}
|
||||
|
||||
public FormBinder createFormBinder(Scenario currentScenario,
|
||||
IResourceAllocationModel resourceAllocationModel) {
|
||||
if (formBinder != null) {
|
||||
throw new IllegalStateException(
|
||||
"there is already a binder associated with this object");
|
||||
public FormBinder createFormBinder(Scenario currentScenario, IResourceAllocationModel resourceAllocationModel) {
|
||||
if ( formBinder != null ) {
|
||||
throw new IllegalStateException("there is already a binder associated with this object");
|
||||
}
|
||||
formBinder = new FormBinder(currentScenario, this,
|
||||
resourceAllocationModel);
|
||||
formBinder = new FormBinder(currentScenario, this, resourceAllocationModel);
|
||||
return formBinder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,9 +104,9 @@ public class FormBinder {
|
|||
@Override
|
||||
public void onEvent(Event event) {
|
||||
Component target = event.getTarget();
|
||||
if (target instanceof InputElement) {
|
||||
if ( target instanceof InputElement ) {
|
||||
InputElement inputElement = (InputElement) target;
|
||||
if (inputElement.isDisabled()) {
|
||||
if ( inputElement.isDisabled() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -141,7 +141,7 @@ public class FormBinder {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
if (effortInput.isDisabled()) {
|
||||
if ( effortInput.isDisabled() ) {
|
||||
effortInput.setValue(sumAllEffortFromInputs(rows));
|
||||
}
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ public class FormBinder {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
if (allResourcesPerDay.isDisabled()) {
|
||||
if ( allResourcesPerDay.isDisabled() ) {
|
||||
sumResourcesPerDayFromRowsAndAssignToAllResourcesPerDay();
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ public class FormBinder {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
if (!effortInput.isDisabled()) {
|
||||
if ( !effortInput.isDisabled() ) {
|
||||
distributeHoursFromTotalToRows();
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ public class FormBinder {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
if (!allResourcesPerDay.isDisabled()) {
|
||||
if ( !allResourcesPerDay.isDisabled() ) {
|
||||
distributeResourcesPerDayToRows();
|
||||
}
|
||||
}
|
||||
|
|
@ -187,18 +187,16 @@ public class FormBinder {
|
|||
|
||||
private Button advancedSearchButton;
|
||||
|
||||
public FormBinder(Scenario currentScenario,
|
||||
AllocationRowsHandler allocationRowsHandler,
|
||||
IResourceAllocationModel resourceAllocationModel) {
|
||||
public FormBinder(Scenario currentScenario, AllocationRowsHandler allocationRowsHandler,
|
||||
IResourceAllocationModel resourceAllocationModel) {
|
||||
|
||||
this.allocationRowsHandler = allocationRowsHandler;
|
||||
this.resourceAllocationModel = resourceAllocationModel;
|
||||
this.lastAllocation = this.allocationRowsHandler
|
||||
.getInitialAllocation(currentScenario);
|
||||
this.lastAllocation = this.allocationRowsHandler.getInitialAllocation(currentScenario);
|
||||
this.aggregate = this.lastAllocation.getAggregate();
|
||||
}
|
||||
|
||||
public void setAssignedEffortComponent(
|
||||
EffortDurationBox assignedEffortComponent) {
|
||||
public void setAssignedEffortComponent(EffortDurationBox assignedEffortComponent) {
|
||||
this.effortInput = assignedEffortComponent;
|
||||
this.effortInput.setConstraint(positiveValueRequired());
|
||||
allHoursInputComponentDisabilityRule();
|
||||
|
|
@ -268,16 +266,14 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
private void onChangeEnableApply(InputElement inputElement) {
|
||||
Util.ensureUniqueListener(inputElement, Events.ON_CHANGE,
|
||||
onChangeEnableApply);
|
||||
Util.ensureUniqueListener(inputElement, Events.ON_CHANGE, onChangeEnableApply);
|
||||
}
|
||||
|
||||
public void setWorkableDays(Intbox duration,
|
||||
final TaskPropertiesController taskPropertiesController,
|
||||
final Label labelTaskStart, final Label labelTaskEnd) {
|
||||
this.workableDaysAndDatesBinder = new WorkableDaysAndDatesBinder(
|
||||
duration, labelTaskStart, labelTaskEnd,
|
||||
taskPropertiesController);
|
||||
public void setWorkableDays(Intbox duration, final TaskPropertiesController taskPropertiesController,
|
||||
final Label labelTaskStart, final Label labelTaskEnd) {
|
||||
|
||||
this.workableDaysAndDatesBinder =
|
||||
new WorkableDaysAndDatesBinder(duration, labelTaskStart, labelTaskEnd, taskPropertiesController);
|
||||
}
|
||||
|
||||
class WorkableDaysAndDatesBinder {
|
||||
|
|
@ -290,17 +286,15 @@ public class FormBinder {
|
|||
|
||||
private final TaskPropertiesController taskPropertiesController;
|
||||
|
||||
WorkableDaysAndDatesBinder(final Intbox taskWorkableDays,
|
||||
final Label labelTaskStart, final Label labelTaskEnd,
|
||||
WorkableDaysAndDatesBinder(final Intbox taskWorkableDays, final Label labelTaskStart, final Label labelTaskEnd,
|
||||
final TaskPropertiesController taskPropertiesController) {
|
||||
|
||||
this.taskWorkableDays = taskWorkableDays;
|
||||
this.labelTaskStart = labelTaskStart;
|
||||
this.labelTaskEnd = labelTaskEnd;
|
||||
this.taskPropertiesController = taskPropertiesController;
|
||||
initializeDateAndDurationFieldsFromTaskOriginalValues();
|
||||
final LocalDate firstPossibleDay = getTask()
|
||||
.getFirstDayNotConsolidated().nextDayAtStart()
|
||||
.asExclusiveEnd();
|
||||
final LocalDate firstPossibleDay = getTask().getFirstDayNotConsolidated().nextDayAtStart().asExclusiveEnd();
|
||||
Util.ensureUniqueListeners(taskWorkableDays, Events.ON_CHANGE,
|
||||
new EventListener() {
|
||||
|
||||
|
|
@ -308,51 +302,47 @@ public class FormBinder {
|
|||
public void onEvent(Event event) {
|
||||
Task task = getTask();
|
||||
Integer workableDays = taskWorkableDays.getValue();
|
||||
if (allocationRowsHandler.isForwardsAllocation()) {
|
||||
IntraDayDate newEnd = ensureItIsAfterConsolidation(task
|
||||
.calculateEndGivenWorkableDays(workableDays));
|
||||
updateWorkableDaysIfNecessary(workableDays,
|
||||
getTask().getIntraDayStartDate(),
|
||||
newEnd);
|
||||
taskPropertiesController
|
||||
.updateTaskEndDate(newEnd.getDate());
|
||||
showValueOfDateOn(labelTaskEnd,
|
||||
newEnd.getDate());
|
||||
if ( allocationRowsHandler.isForwardsAllocation() ) {
|
||||
|
||||
IntraDayDate newEnd =
|
||||
ensureItIsAfterConsolidation(task.calculateEndGivenWorkableDays(workableDays));
|
||||
|
||||
updateWorkableDaysIfNecessary(workableDays, getTask().getIntraDayStartDate(), newEnd);
|
||||
taskPropertiesController.updateTaskEndDate(newEnd.getDate());
|
||||
showValueOfDateOn(labelTaskEnd, newEnd.getDate());
|
||||
} else {
|
||||
IntraDayDate newStart = ensureItIsAfterConsolidation(task
|
||||
.calculateStartGivenWorkableDays(workableDays));
|
||||
updateWorkableDaysIfNecessary(workableDays,
|
||||
newStart, task.getIntraDayEndDate());
|
||||
taskPropertiesController
|
||||
.updateTaskStartDate(newStart.getDate());
|
||||
showValueOfDateOn(labelTaskStart,
|
||||
newStart.getDate());
|
||||
|
||||
IntraDayDate newStart =
|
||||
ensureItIsAfterConsolidation(task.calculateStartGivenWorkableDays(workableDays));
|
||||
|
||||
updateWorkableDaysIfNecessary(workableDays, newStart, task.getIntraDayEndDate());
|
||||
taskPropertiesController.updateTaskStartDate(newStart.getDate());
|
||||
showValueOfDateOn(labelTaskStart, newStart.getDate());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWorkableDaysIfNecessary(
|
||||
int specifiedWorkableDays,
|
||||
IntraDayDate allocationStart,
|
||||
IntraDayDate allocationEnd) {
|
||||
Integer effectiveWorkableDays = getTask()
|
||||
.getWorkableDaysFrom(
|
||||
private void updateWorkableDaysIfNecessary(int specifiedWorkableDays,
|
||||
IntraDayDate allocationStart,
|
||||
IntraDayDate allocationEnd) {
|
||||
|
||||
Integer effectiveWorkableDays = getTask().getWorkableDaysFrom(
|
||||
allocationStart.getDate(),
|
||||
allocationEnd.asExclusiveEnd());
|
||||
if (effectiveWorkableDays < specifiedWorkableDays) {
|
||||
|
||||
if ( effectiveWorkableDays < specifiedWorkableDays ) {
|
||||
Clients.response(new AuWrongValue(
|
||||
taskWorkableDays,
|
||||
_("The original workable days value {0} cannot be modified as it has consolidations",
|
||||
specifiedWorkableDays)));
|
||||
taskWorkableDays
|
||||
.setValue(effectiveWorkableDays);
|
||||
specifiedWorkableDays)) );
|
||||
taskWorkableDays.setValue(effectiveWorkableDays);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private IntraDayDate ensureItIsAfterConsolidation(
|
||||
IntraDayDate newDate) {
|
||||
if (getTask().hasConsolidations()) {
|
||||
return Collections.max(Arrays.asList(newDate,
|
||||
private IntraDayDate ensureItIsAfterConsolidation(IntraDayDate newDate) {
|
||||
if ( getTask().hasConsolidations() ) {
|
||||
return Collections.max(
|
||||
Arrays.asList(newDate,
|
||||
IntraDayDate.startOfDay(firstPossibleDay)));
|
||||
}
|
||||
return newDate;
|
||||
|
|
@ -363,9 +353,9 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
void applyDisabledRules() {
|
||||
this.taskWorkableDays.setDisabled(allocationRowsHandler
|
||||
.getCalculatedValue() == CalculatedValue.END_DATE
|
||||
|| isAnyManual() || isTaskUpdatedFromTimesheets());
|
||||
this.taskWorkableDays.setDisabled(allocationRowsHandler.getCalculatedValue() == CalculatedValue.END_DATE ||
|
||||
isAnyManual() ||
|
||||
isTaskUpdatedFromTimesheets());
|
||||
}
|
||||
|
||||
private void initializeDateAndDurationFieldsFromTaskOriginalValues() {
|
||||
|
|
@ -514,14 +504,15 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
public void doApply() {
|
||||
AllocationResult allocationResult = resourceAllocationModel
|
||||
.onAllocationContext(new IResourceAllocationContext<AllocationResult>() {
|
||||
AllocationResult allocationResult =
|
||||
resourceAllocationModel.onAllocationContext(new IResourceAllocationContext<AllocationResult>() {
|
||||
|
||||
@Override
|
||||
public AllocationResult doInsideTransaction() {
|
||||
return allocationRowsHandler.doAllocation().getValue();
|
||||
}
|
||||
});
|
||||
|
||||
allocationProduced(allocationResult);
|
||||
|
||||
TaskPropertiesController.allocationResult = allocationResult;
|
||||
|
|
@ -533,15 +524,14 @@ public class FormBinder {
|
|||
* exit the edition form
|
||||
*/
|
||||
public boolean accept() {
|
||||
if (isTaskUpdatedFromTimesheets()) {
|
||||
if ( isTaskUpdatedFromTimesheets() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Flagged<AllocationResult, Warnings> result = resourceAllocationModel
|
||||
.accept();
|
||||
Flagged<AllocationResult, Warnings> result = resourceAllocationModel.accept();
|
||||
|
||||
// result can be null when editing milestones
|
||||
if (result != null && result.isFlagged()) {
|
||||
if ( result != null && result.isFlagged() ) {
|
||||
allocationProduced(result.getValue());
|
||||
}
|
||||
return result == null || !result.isFlagged();
|
||||
|
|
@ -565,11 +555,10 @@ public class FormBinder {
|
|||
@SuppressWarnings("unchecked")
|
||||
private void loadSclassRowSatisfied() {
|
||||
try {
|
||||
List<org.zkoss.zul.Row> rows = (List<org.zkoss.zul.Row>) allocationsGrid
|
||||
.getRows().getChildren();
|
||||
List<org.zkoss.zul.Row> rows = (List<org.zkoss.zul.Row>) allocationsGrid.getRows().getChildren();
|
||||
for (org.zkoss.zul.Row row : rows) {
|
||||
if (row.getValue() instanceof AllocationRow) {
|
||||
if (!((AllocationRow) row.getValue()).isSatisfied()) {
|
||||
if ( row.getValue() instanceof AllocationRow ) {
|
||||
if ( !((AllocationRow) row.getValue()).isSatisfied() ) {
|
||||
row.setSclass("allocation-not-satisfied");
|
||||
} else {
|
||||
row.setSclass("allocation-satisfied");
|
||||
|
|
@ -616,13 +605,12 @@ public class FormBinder {
|
|||
FormBinder.this.applyButton.setDisabled(true);
|
||||
}
|
||||
};
|
||||
Util.ensureUniqueListener(this.applyButton, Events.ON_CLICK,
|
||||
applyButtonListener);
|
||||
Util.ensureUniqueListener(this.applyButton, Events.ON_CLICK, applyButtonListener);
|
||||
}
|
||||
|
||||
public EffortDuration getAssignedEffort() {
|
||||
EffortDuration result = effortInput.getEffortDurationValue();
|
||||
if (result == null) {
|
||||
if ( result == null ) {
|
||||
throw new RuntimeException("assignedHoursComponent returns null");
|
||||
}
|
||||
return result;
|
||||
|
|
@ -668,30 +656,24 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
public void markNoResourcesMatchedByCriterions(ResourceEnum resourceType,
|
||||
Collection<? extends Criterion> criterions) {
|
||||
messagesForUser
|
||||
.showMessage(
|
||||
Level.ERROR,
|
||||
Collection<? extends Criterion> criterions) {
|
||||
messagesForUser.showMessage(Level.ERROR,
|
||||
_("there are no resources for required criteria: {0}. So the generic allocation can't be added",
|
||||
Criterion.getCaptionFor(resourceType,
|
||||
criterions)));
|
||||
Criterion.getCaptionFor(resourceType, criterions)));
|
||||
}
|
||||
|
||||
public void markThereisAlreadyAssignmentWith(ResourceEnum resourceType,
|
||||
Collection<? extends Criterion> criterions) {
|
||||
messagesForUser.showMessage(
|
||||
Level.ERROR,
|
||||
_("already exists an allocation for criteria {0}",
|
||||
Criterion.getCaptionFor(resourceType, criterions)));
|
||||
Collection<? extends Criterion> criterions) {
|
||||
messagesForUser.showMessage(Level.ERROR,
|
||||
_("already exists an allocation for criteria {0}", Criterion.getCaptionFor(resourceType, criterions)));
|
||||
}
|
||||
|
||||
public void markNoEmptyResourcesPerDay(List<AllocationRow> rows) {
|
||||
Validate.isTrue(!rows.isEmpty());
|
||||
final String message = _("resources per day cannot be empty or less than zero");
|
||||
if (!recommendedAllocation) {
|
||||
if ( !recommendedAllocation ) {
|
||||
AllocationRow first = rows.get(0);
|
||||
throw new WrongValueException(
|
||||
first.getIntendedResourcesPerDayInput(), message);
|
||||
throw new WrongValueException(first.getIntendedResourcesPerDayInput(), message);
|
||||
} else {
|
||||
throw new WrongValueException(allResourcesPerDay, message);
|
||||
}
|
||||
|
|
@ -706,20 +688,17 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
public void detach() {
|
||||
if (this.applyButton != null) {
|
||||
this.applyButton.removeEventListener(Events.ON_CLICK,
|
||||
applyButtonListener);
|
||||
if ( this.applyButton != null ) {
|
||||
this.applyButton.removeEventListener(Events.ON_CLICK, applyButtonListener);
|
||||
}
|
||||
for (InputElement inputElement : inputsAssociatedWithOnChangeEnableApply) {
|
||||
inputElement.removeEventListener(Events.ON_CHANGE,
|
||||
onChangeEnableApply);
|
||||
inputElement.removeEventListener(Events.ON_CHANGE, onChangeEnableApply);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRecommendedAllocation(Button recommendedAllocation) {
|
||||
this.btnRecommendedAllocation = recommendedAllocation;
|
||||
this.btnRecommendedAllocation.setDisabled(isAnyManual()
|
||||
|| isTaskUpdatedFromTimesheets());
|
||||
this.btnRecommendedAllocation.setDisabled(isAnyManual() || isTaskUpdatedFromTimesheets());
|
||||
Util.ensureUniqueListener(recommendedAllocation, Events.ON_CLICK,
|
||||
new EventListener() {
|
||||
@Override
|
||||
|
|
@ -740,26 +719,27 @@ public class FormBinder {
|
|||
|
||||
private void activatingRecommendedAllocation() {
|
||||
allocationRowsHandler.removeAll();
|
||||
ProportionalDistributor distributor = resourceAllocationModel
|
||||
.addDefaultAllocations();
|
||||
ProportionalDistributor distributor = resourceAllocationModel.addDefaultAllocations();
|
||||
boolean recommendAllocationSuccessful = distributor != null;
|
||||
if (recommendAllocationSuccessful) {
|
||||
|
||||
if ( recommendAllocationSuccessful ) {
|
||||
hoursDistributorForRecommendedAllocation = distributor;
|
||||
resourcesPerDayDistributorForRecommendedAllocation = ResourcesPerDay
|
||||
.distributor(hoursDistributorForRecommendedAllocation);
|
||||
|
||||
resourcesPerDayDistributorForRecommendedAllocation =
|
||||
ResourcesPerDay.distributor(hoursDistributorForRecommendedAllocation);
|
||||
|
||||
this.recommendedAllocation = true;
|
||||
disableIfNeededWorkerSearch();
|
||||
applyDisabledRules();
|
||||
effortInput.addEventListener(Events.ON_CHANGE, allHoursInputChange);
|
||||
allResourcesPerDay.addEventListener(Events.ON_CHANGE,
|
||||
allResourcesPerDayChange);
|
||||
allResourcesPerDay.addEventListener(Events.ON_CHANGE, allResourcesPerDayChange);
|
||||
resetStateForResourcesPerDayInputsWhenDoingRecommendedAllocation();
|
||||
}
|
||||
Util.reloadBindings(allocationsGrid);
|
||||
}
|
||||
|
||||
private void resetStateForResourcesPerDayInputsWhenDoingRecommendedAllocation() {
|
||||
if (allResourcesPerDay.isDisabled()) {
|
||||
if ( allResourcesPerDay.isDisabled() ) {
|
||||
allResourcesPerDay.setValue((BigDecimal) null);
|
||||
AllocationRow.unknownResourcesPerDay(rows);
|
||||
} else {
|
||||
|
|
@ -800,8 +780,7 @@ public class FormBinder {
|
|||
private void deactivatingRecommendedAllocation() {
|
||||
this.recommendedAllocation = false;
|
||||
effortInput.removeEventListener(Events.ON_CHANGE, allHoursInputChange);
|
||||
allResourcesPerDay.removeEventListener(Events.ON_CHANGE,
|
||||
allResourcesPerDayChange);
|
||||
allResourcesPerDay.removeEventListener(Events.ON_CHANGE, allResourcesPerDayChange);
|
||||
applyDisabledRules();
|
||||
disableIfNeededWorkerSearch();
|
||||
}
|
||||
|
|
@ -822,14 +801,13 @@ public class FormBinder {
|
|||
this.advancedSearchButton.setDisabled(recommendedAllocation);
|
||||
}
|
||||
|
||||
public void setNewAllocationSelectorCombo(
|
||||
NewAllocationSelectorCombo newAllocationSelectorCombo) {
|
||||
public void setNewAllocationSelectorCombo(NewAllocationSelectorCombo newAllocationSelectorCombo) {
|
||||
this.newAllocationSelectorCombo = newAllocationSelectorCombo;
|
||||
this.newAllocationSelectorCombo.setDisabled(recommendedAllocation);
|
||||
}
|
||||
|
||||
private void sumResourcesPerDayFromRowsAndAssignToAllResourcesPerDay() {
|
||||
if (allResourcesPerDay.isDisabled()) {
|
||||
if ( allResourcesPerDay.isDisabled() ) {
|
||||
allResourcesPerDay.setValue(sumResourcesPerDayFromInputs());
|
||||
}
|
||||
}
|
||||
|
|
@ -837,7 +815,7 @@ public class FormBinder {
|
|||
private BigDecimal sumResourcesPerDayFromInputs() {
|
||||
BigDecimal sum = BigDecimal.ZERO;
|
||||
for (AllocationRow each : rows) {
|
||||
if (each.getIntendedResourcesPerDayInput().isValid()) {
|
||||
if ( each.getIntendedResourcesPerDayInput().isValid() ) {
|
||||
sum = sum.add(each.getResourcesPerDayFromInput().getAmount());
|
||||
}
|
||||
}
|
||||
|
|
@ -892,8 +870,7 @@ public class FormBinder {
|
|||
return allTotalResourcesPerDay;
|
||||
}
|
||||
|
||||
public void setAllConsolidatedResourcesPerDay(
|
||||
Label allConsolidatedResourcesPerDay) {
|
||||
public void setAllConsolidatedResourcesPerDay(Label allConsolidatedResourcesPerDay) {
|
||||
this.allConsolidatedResourcesPerDay = allConsolidatedResourcesPerDay;
|
||||
}
|
||||
|
||||
|
|
@ -903,17 +880,12 @@ public class FormBinder {
|
|||
|
||||
public void loadAggregatedCalculations() {
|
||||
// Calculate aggregated values
|
||||
if (behaviour.allowMultipleSelection()) {
|
||||
allOriginalEffort.setValue(sumAllOriginalEffort(this.rows)
|
||||
.toFormattedString());
|
||||
allTotalEffort.setValue(sumAllTotalEffort(this.rows)
|
||||
.toFormattedString());
|
||||
allConsolidatedEffort.setValue(AllocationRow
|
||||
.sumAllConsolidatedEffort(this.rows).toFormattedString());
|
||||
allTotalResourcesPerDay.setValue(sumAllTotalResourcesPerDay()
|
||||
.toString());
|
||||
allConsolidatedResourcesPerDay
|
||||
.setValue(sumAllConsolidatedResourcesPerDay().toString());
|
||||
if ( behaviour.allowMultipleSelection() ) {
|
||||
allOriginalEffort.setValue(sumAllOriginalEffort(this.rows).toFormattedString());
|
||||
allTotalEffort.setValue(sumAllTotalEffort(this.rows).toFormattedString());
|
||||
allConsolidatedEffort.setValue(AllocationRow.sumAllConsolidatedEffort(this.rows).toFormattedString());
|
||||
allTotalResourcesPerDay.setValue(sumAllTotalResourcesPerDay().toString());
|
||||
allConsolidatedResourcesPerDay.setValue(sumAllConsolidatedResourcesPerDay().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -922,10 +894,8 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
public void cannotAllocateMoreThanOneResource(List<Resource> resources) {
|
||||
messagesForUser.showMessage(
|
||||
Level.ERROR,
|
||||
_("{0} could not be allocated. "
|
||||
+ "Cannot allocate more than one resource",
|
||||
messagesForUser.showMessage(Level.ERROR,
|
||||
_("{0} could not be allocated. " + "Cannot allocate more than one resource",
|
||||
Resource.getCaptionFor(resources)));
|
||||
}
|
||||
|
||||
|
|
@ -934,9 +904,8 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
public boolean isAnyNotFlat() {
|
||||
for (AllocationRow allocationRow : allocationRowsHandler
|
||||
.getCurrentRows()) {
|
||||
if (allocationRow.isAssignmentFunctionNotFlat()) {
|
||||
for (AllocationRow allocationRow : allocationRowsHandler.getCurrentRows()) {
|
||||
if ( allocationRow.isAssignmentFunctionNotFlat() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -944,9 +913,8 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
public boolean isAnyManual() {
|
||||
for (AllocationRow allocationRow : allocationRowsHandler
|
||||
.getCurrentRows()) {
|
||||
if (allocationRow.isAssignmentFunctionManual()) {
|
||||
for (AllocationRow allocationRow : allocationRowsHandler.getCurrentRows()) {
|
||||
if ( allocationRow.isAssignmentFunctionManual() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,18 +53,15 @@ public class ResourceAllocationCommand implements IResourceAllocationCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement) {
|
||||
public void doAction(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement) {
|
||||
editTaskUtilities.reattach(taskElement);
|
||||
|
||||
if (isApplicableTo(taskElement)) {
|
||||
if ( isApplicableTo(taskElement) ) {
|
||||
Task task = (Task) taskElement;
|
||||
if (task.isSubcontracted()) {
|
||||
editTaskController.showEditFormSubcontract(context, task,
|
||||
planningState);
|
||||
if ( task.isSubcontracted() ) {
|
||||
editTaskController.showEditFormSubcontract(context, task, planningState);
|
||||
} else {
|
||||
editTaskController.showEditFormResourceAllocation(context,
|
||||
task, planningState);
|
||||
editTaskController.showEditFormResourceAllocation(context, task, planningState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,8 +72,7 @@ public class ResourceAllocationCommand implements IResourceAllocationCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(EditTaskController editTaskController,
|
||||
PlanningState planningState) {
|
||||
public void initialize(EditTaskController editTaskController, PlanningState planningState) {
|
||||
this.editTaskController = editTaskController;
|
||||
this.planningState = planningState;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.libreplan.business.planner.entities.DerivedAllocation;
|
|||
import org.libreplan.business.planner.entities.ResourceAllocation;
|
||||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
import org.libreplan.business.resources.entities.ResourceEnum;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.web.I18nHelper;
|
||||
import org.libreplan.web.common.EffortDurationBox;
|
||||
import org.libreplan.web.common.IMessagesForUser;
|
||||
|
|
@ -93,8 +94,7 @@ import org.zkoss.zul.Window;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class ResourceAllocationController extends GenericForwardComposer {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(ResourceAllocationController.class);
|
||||
private static final Log LOG = LogFactory.getLog(ResourceAllocationController.class);
|
||||
|
||||
private IResourceAllocationModel resourceAllocationModel;
|
||||
|
||||
|
|
@ -177,18 +177,15 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
* @param ganttTask
|
||||
* @param planningState
|
||||
*/
|
||||
public void init(IContextWithPlannerTask<TaskElement> context,
|
||||
org.libreplan.business.planner.entities.Task task,
|
||||
PlanningState planningState, IMessagesForUser messagesForUser) {
|
||||
public void init(IContextWithPlannerTask<TaskElement> context, Task task, PlanningState planningState,
|
||||
IMessagesForUser messagesForUser) {
|
||||
try {
|
||||
if (formBinder != null) {
|
||||
if ( formBinder != null ) {
|
||||
formBinder.detach();
|
||||
}
|
||||
allocationRows = resourceAllocationModel.initAllocationsFor(task,
|
||||
context, planningState);
|
||||
allocationRows = resourceAllocationModel.initAllocationsFor(task, context, planningState);
|
||||
|
||||
formBinder = allocationRows.createFormBinder(planningState
|
||||
.getCurrentScenario(), resourceAllocationModel);
|
||||
formBinder = allocationRows.createFormBinder(planningState.getCurrentScenario(), resourceAllocationModel);
|
||||
formBinder.setBehaviour(ResourceAllocationBehaviour.NON_LIMITING);
|
||||
formBinder.setAllOriginalEffort(allOriginalEffort);
|
||||
formBinder.setAllTotalEffort(allTotalEffort);
|
||||
|
|
@ -196,21 +193,17 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
formBinder.setAssignedEffortComponent(assignedEffortComponent);
|
||||
|
||||
formBinder.setAllTotalResourcesPerDay(allTotalResourcesPerDay);
|
||||
formBinder
|
||||
.setAllConsolidatedResourcesPerDay(allConsolidatedResourcesPerDay);
|
||||
formBinder.setAllConsolidatedResourcesPerDay(allConsolidatedResourcesPerDay);
|
||||
formBinder.setAllResourcesPerDay(allResourcesPerDay);
|
||||
|
||||
TaskPropertiesController taskPropertiesController = editTaskController
|
||||
.getTaskPropertiesController();
|
||||
formBinder.setWorkableDays(getTaskWorkableDays(),
|
||||
taskPropertiesController, getTaskStart(), getTaskEnd());
|
||||
TaskPropertiesController taskPropertiesController = editTaskController.getTaskPropertiesController();
|
||||
formBinder.setWorkableDays(getTaskWorkableDays(), taskPropertiesController, getTaskStart(), getTaskEnd());
|
||||
|
||||
formBinder.setApplyButton(applyButton);
|
||||
formBinder.setAllocationsGrid(allocationsGrid);
|
||||
formBinder.setMessagesForUser(messagesForUser);
|
||||
formBinder.setWorkerSearchTab(workerSearchTab);
|
||||
formBinder
|
||||
.setNewAllocationSelectorCombo(newAllocationSelectorCombo);
|
||||
formBinder.setNewAllocationSelectorCombo(newAllocationSelectorCombo);
|
||||
|
||||
initializeTaskInformationComponent();
|
||||
initializeAllocationConfigurationComponent();
|
||||
|
|
@ -219,8 +212,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
tbResourceAllocation.setSelected(true);
|
||||
|
||||
newAllocationSelector.setAllocationsAdder(resourceAllocationModel);
|
||||
newAllocationSelectorCombo
|
||||
.setAllocationsAdder(resourceAllocationModel);
|
||||
newAllocationSelectorCombo.setAllocationsAdder(resourceAllocationModel);
|
||||
|
||||
Util.reloadBindings(allocationsGrid);
|
||||
} catch (WrongValueException e) {
|
||||
|
|
@ -234,13 +226,11 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public Label getTaskStart() {
|
||||
return (allocationConfiguration != null) ? allocationConfiguration
|
||||
.getTaskStart() : null;
|
||||
return (allocationConfiguration != null) ? allocationConfiguration.getTaskStart() : null;
|
||||
}
|
||||
|
||||
public Label getTaskEnd() {
|
||||
return (allocationConfiguration != null) ? allocationConfiguration
|
||||
.getTaskEnd() : null;
|
||||
return (allocationConfiguration != null) ? allocationConfiguration.getTaskEnd() : null;
|
||||
}
|
||||
|
||||
private Radiogroup getCalculationTypeSelector() {
|
||||
|
|
@ -248,10 +238,8 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
private void initializeTaskInformationComponent() {
|
||||
taskInformation.initializeGridTaskRows(resourceAllocationModel
|
||||
.getHoursAggregatedByCriterions());
|
||||
formBinder.setRecommendedAllocation(taskInformation
|
||||
.getBtnRecommendedAllocation());
|
||||
taskInformation.initializeGridTaskRows(resourceAllocationModel.getHoursAggregatedByCriterions());
|
||||
formBinder.setRecommendedAllocation(taskInformation.getBtnRecommendedAllocation());
|
||||
taskInformation.onCalculateTotalHours(new ITotalHoursCalculationListener() {
|
||||
|
||||
@Override
|
||||
|
|
@ -269,23 +257,20 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
|
||||
CRITERIONS {
|
||||
@Override
|
||||
public Component cell(HoursRendererColumn column,
|
||||
AggregatedHoursGroup data) {
|
||||
public Component cell(HoursRendererColumn column, AggregatedHoursGroup data) {
|
||||
return new Label(data.getCriterionsJoinedByComma());
|
||||
}
|
||||
},
|
||||
RESOURCE_TYPE{
|
||||
|
||||
@Override
|
||||
public Component cell(HoursRendererColumn column,
|
||||
AggregatedHoursGroup data) {
|
||||
public Component cell(HoursRendererColumn column, AggregatedHoursGroup data) {
|
||||
return new Label(asString(data.getResourceType()));
|
||||
}
|
||||
},
|
||||
HOURS {
|
||||
@Override
|
||||
public Component cell(HoursRendererColumn column,
|
||||
AggregatedHoursGroup data) {
|
||||
public Component cell(HoursRendererColumn column, AggregatedHoursGroup data) {
|
||||
Label result = new Label(Integer.toString(data.getHours()));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -293,17 +278,19 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
|
||||
private static String asString(ResourceEnum resourceType) {
|
||||
switch (resourceType) {
|
||||
|
||||
case MACHINE:
|
||||
|
||||
case WORKER:
|
||||
return _(resourceType.getDisplayName());
|
||||
|
||||
default:
|
||||
LOG.warn("no i18n for " + resourceType.name());
|
||||
return resourceType.name();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Component cell(HoursRendererColumn column,
|
||||
AggregatedHoursGroup data);
|
||||
public abstract Component cell(HoursRendererColumn column, AggregatedHoursGroup data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -70,14 +70,13 @@ import org.zkoss.zk.ui.Executions;
|
|||
public abstract class ChartFiller implements IChartFiller {
|
||||
|
||||
protected abstract class EffortByDayCalculator<T> {
|
||||
public SortedMap<LocalDate, EffortDuration> calculate(
|
||||
Collection<? extends T> elements) {
|
||||
public SortedMap<LocalDate, EffortDuration> calculate(Collection<? extends T> elements) {
|
||||
SortedMap<LocalDate, EffortDuration> result = new TreeMap<LocalDate, EffortDuration>();
|
||||
if (elements.isEmpty()) {
|
||||
if ( elements.isEmpty() ) {
|
||||
return result;
|
||||
}
|
||||
for (T element : elements) {
|
||||
if (included(element)) {
|
||||
if ( included(element) ) {
|
||||
EffortDuration duration = getDurationFor(element);
|
||||
LocalDate day = getDayFor(element);
|
||||
EffortDuration previous = result.get(day);
|
||||
|
|
|
|||
|
|
@ -182,9 +182,8 @@ public abstract class EarnedValueChartFiller extends ChartFiller {
|
|||
indicators.put(type, calculatedValueForEveryDay(values, interval));
|
||||
}
|
||||
|
||||
protected void addZeroBeforeTheFirstValue(
|
||||
SortedMap<LocalDate, BigDecimal> map) {
|
||||
if (!map.isEmpty()) {
|
||||
protected void addZeroBeforeTheFirstValue(SortedMap<LocalDate, BigDecimal> map) {
|
||||
if ( !map.isEmpty() ) {
|
||||
map.put(map.firstKey().minusDays(1), BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
|
|
@ -204,7 +203,7 @@ public abstract class EarnedValueChartFiller extends ChartFiller {
|
|||
plotinfos.add(plotinfo);
|
||||
}
|
||||
|
||||
if (plotinfos.isEmpty()) {
|
||||
if ( plotinfos.isEmpty() ) {
|
||||
// If user doesn't select any indicator, it is needed to create
|
||||
// a default Plotinfo in order to avoid errors on Timemplot
|
||||
plotinfos.add(new Plotinfo());
|
||||
|
|
@ -233,8 +232,7 @@ public abstract class EarnedValueChartFiller extends ChartFiller {
|
|||
public LocalDate initialDateForIndicatorValues() {
|
||||
Interval chartInterval = getIndicatorsDefinitionInterval();
|
||||
LocalDate today = new LocalDate();
|
||||
return includes(chartInterval, today) ? today : chartInterval
|
||||
.getFinish().minusDays(1);
|
||||
return includes(chartInterval, today) ? today : chartInterval.getFinish().minusDays(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,8 +63,7 @@ import org.zkoss.zul.Tab;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class LimitingResourceAllocationController extends GenericForwardComposer {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(LimitingResourceAllocationController.class);
|
||||
private static final Log LOG = LogFactory.getLog(LimitingResourceAllocationController.class);
|
||||
|
||||
@Autowired
|
||||
private ILimitingResourceAllocationModel resourceAllocationModel;
|
||||
|
|
|
|||
|
|
@ -267,8 +267,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private String tabSelected = "load_tab";
|
||||
|
||||
private static class NullSeparatorCommandOnTask<T> implements
|
||||
ICommandOnTask<T> {
|
||||
private static class NullSeparatorCommandOnTask<T> implements ICommandOnTask<T> {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
@ -294,37 +293,36 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void setConfigurationToPlanner(final Planner planner, Order order,
|
||||
ViewSwitcher switcher,
|
||||
EditTaskController editTaskController,
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController,
|
||||
AdvanceAssignmentPlanningController advanceAssignmentPlanningController,
|
||||
AdvanceConsolidationController advanceConsolidationController,
|
||||
CalendarAllocationController calendarAllocationController,
|
||||
List<ICommand<TaskElement>> additional) {
|
||||
public void setConfigurationToPlanner(final Planner planner,
|
||||
Order order,
|
||||
ViewSwitcher switcher,
|
||||
EditTaskController editTaskController,
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController,
|
||||
AdvanceAssignmentPlanningController advanceAssignmentPlanningController,
|
||||
AdvanceConsolidationController advanceConsolidationController,
|
||||
CalendarAllocationController calendarAllocationController,
|
||||
List<ICommand<TaskElement>> additional) {
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
this.planner = planner;
|
||||
planningState = createPlanningStateFor(order);
|
||||
PlannerConfiguration<TaskElement> configuration = planningState
|
||||
.getConfiguration();
|
||||
PROFILING_LOG.debug("load data and create configuration took: "
|
||||
+ (System.currentTimeMillis() - time) + " ms");
|
||||
PlannerConfiguration<TaskElement> configuration = planningState.getConfiguration();
|
||||
PROFILING_LOG.debug("load data and create configuration took: " + (System.currentTimeMillis() - time) + " ms");
|
||||
User user;
|
||||
|
||||
try {
|
||||
user = this.userDAO.findByLoginName(SecurityUtils
|
||||
.getSessionUserLoginName());
|
||||
user = this.userDAO.findByLoginName(SecurityUtils.getSessionUserLoginName());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
configuration.setExpandPlanningViewCharts(user
|
||||
.isExpandOrderPlanningViewCharts());
|
||||
|
||||
configuration.setExpandPlanningViewCharts(user.isExpandOrderPlanningViewCharts());
|
||||
addAdditional(additional, configuration);
|
||||
|
||||
planner.setInitialZoomLevel(getZoomLevel(configuration, order));
|
||||
|
||||
final boolean writingAllowed = isWritingAllowedOnOrder();
|
||||
ISaveCommand saveCommand = setupSaveCommand(configuration,
|
||||
writingAllowed);
|
||||
ISaveCommand saveCommand = setupSaveCommand(configuration, writingAllowed);
|
||||
setupEditingCapabilities(configuration, writingAllowed);
|
||||
|
||||
configuration.addGlobalCommand(buildReassigningCommand());
|
||||
|
|
@ -335,25 +333,21 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
final IResourceAllocationCommand resourceAllocationCommand = buildResourceAllocationCommand(editTaskController);
|
||||
|
||||
final IAdvanceAssignmentPlanningCommand advanceAssignmentPlanningCommand = buildAdvanceAssignmentPlanningCommand(advanceAssignmentPlanningController);
|
||||
final IAdvanceAssignmentPlanningCommand advanceAssignmentPlanningCommand =
|
||||
buildAdvanceAssignmentPlanningCommand(advanceAssignmentPlanningController);
|
||||
|
||||
// Build context menu
|
||||
configuration.addCommandOnTask(buildMilestoneCommand());
|
||||
configuration.addCommandOnTask(buildDeleteMilestoneCommand());
|
||||
configuration.addCommandOnTask(separator);
|
||||
configuration
|
||||
.addCommandOnTask(buildTaskPropertiesCommand(editTaskController));
|
||||
configuration.addCommandOnTask(buildTaskPropertiesCommand(editTaskController));
|
||||
configuration.addCommandOnTask(resourceAllocationCommand);
|
||||
configuration
|
||||
.addCommandOnTask(buildAdvancedAllocationCommand(advancedAllocationTaskController));
|
||||
configuration
|
||||
.addCommandOnTask(buildSubcontractCommand(editTaskController));
|
||||
configuration
|
||||
.addCommandOnTask(buildCalendarAllocationCommand(calendarAllocationController));
|
||||
configuration.addCommandOnTask(buildAdvancedAllocationCommand(advancedAllocationTaskController));
|
||||
configuration.addCommandOnTask(buildSubcontractCommand(editTaskController));
|
||||
configuration.addCommandOnTask(buildCalendarAllocationCommand(calendarAllocationController));
|
||||
configuration.addCommandOnTask(separator);
|
||||
configuration.addCommandOnTask(advanceAssignmentPlanningCommand);
|
||||
configuration
|
||||
.addCommandOnTask(buildAdvanceConsolidationCommand(advanceConsolidationController));
|
||||
configuration.addCommandOnTask(buildAdvanceConsolidationCommand(advanceConsolidationController));
|
||||
|
||||
configuration.setDoubleClickCommand(resourceAllocationCommand);
|
||||
addPrintSupport(configuration, order);
|
||||
|
|
@ -366,8 +360,10 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
configureModificators(planningState.getOrder(), configuration);
|
||||
long setConfigurationTime = System.currentTimeMillis();
|
||||
planner.setConfiguration(configuration);
|
||||
PROFILING_LOG.debug("setConfiguration on planner took: "
|
||||
+ (System.currentTimeMillis() - setConfigurationTime) + " ms");
|
||||
|
||||
PROFILING_LOG.debug("setConfiguration on planner took: " +
|
||||
(System.currentTimeMillis() - setConfigurationTime) + " ms");
|
||||
|
||||
long preparingChartsAndMisc = System.currentTimeMillis();
|
||||
|
||||
setupZoomLevelListener(planner, order);
|
||||
|
|
@ -389,37 +385,31 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
ChangeHooker changeHooker = new ChangeHooker(configuration, saveCommand);
|
||||
|
||||
setupLoadChart(chartLoadTimeplot, planner, changeHooker);
|
||||
setupEarnedValueChart(chartEarnedValueTimeplot, earnedValueChartFiller,
|
||||
planner, changeHooker);
|
||||
setupEarnedValueChart(chartEarnedValueTimeplot, earnedValueChartFiller, planner, changeHooker);
|
||||
setupAdvanceAssignmentPlanningController(planner, advanceAssignmentPlanningController);
|
||||
PROFILING_LOG
|
||||
.debug("preparing charts and miscellaneous took: "
|
||||
+ (System.currentTimeMillis() - preparingChartsAndMisc)
|
||||
+ " ms");
|
||||
|
||||
PROFILING_LOG.debug("preparing charts and miscellaneous took: " +
|
||||
(System.currentTimeMillis() - preparingChartsAndMisc) + " ms");
|
||||
|
||||
// Calculate critical path progress, needed for 'Project global progress' chart in Dashboard view
|
||||
planner.addGraphChangeListenersFromConfiguration(configuration);
|
||||
long overalProgressContentTime = System.currentTimeMillis();
|
||||
PROFILING_LOG.debug("overalProgressContent took: "
|
||||
+ (System.currentTimeMillis() - overalProgressContentTime));
|
||||
PROFILING_LOG.debug("overalProgressContent took: " + (System.currentTimeMillis() - overalProgressContentTime));
|
||||
}
|
||||
|
||||
private ZoomLevel getZoomLevel(
|
||||
PlannerConfiguration<TaskElement> configuration, Order order) {
|
||||
private ZoomLevel getZoomLevel(PlannerConfiguration<TaskElement> configuration, Order order) {
|
||||
ZoomLevel sessionZoom = FilterUtils.readZoomLevel(order);
|
||||
if (sessionZoom != null) {
|
||||
if ( sessionZoom != null ) {
|
||||
return sessionZoom;
|
||||
}
|
||||
return OrderPlanningModel.calculateDefaultLevel(configuration);
|
||||
}
|
||||
|
||||
private void setupZoomLevelListener(Planner planner, Order order) {
|
||||
planner.getTimeTracker().addZoomListener(
|
||||
getSessionZoomLevelListener(order));
|
||||
planner.getTimeTracker().addZoomListener(getSessionZoomLevelListener(order));
|
||||
}
|
||||
|
||||
private IZoomLevelChangedListener getSessionZoomLevelListener(
|
||||
final Order order) {
|
||||
private IZoomLevelChangedListener getSessionZoomLevelListener(final Order order) {
|
||||
IZoomLevelChangedListener zoomListener = new IZoomLevelChangedListener() {
|
||||
|
||||
@Override
|
||||
|
|
@ -434,7 +424,8 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private OrderEarnedValueChartFiller earnedValueChartFiller;
|
||||
|
||||
private void setupAdvanceAssignmentPlanningController(final Planner planner,
|
||||
private void setupAdvanceAssignmentPlanningController(
|
||||
final Planner planner,
|
||||
AdvanceAssignmentPlanningController advanceAssignmentPlanningController) {
|
||||
|
||||
advanceAssignmentPlanningController.setReloadEarnedValueListener(new IReloadChartListener() {
|
||||
|
|
@ -445,12 +436,13 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
@Override
|
||||
public Void execute() {
|
||||
if (isExecutingOutsideZKExecution()) {
|
||||
if ( isExecutingOutsideZKExecution() ) {
|
||||
return null;
|
||||
}
|
||||
if (planner.isVisibleChart()) {
|
||||
if ( planner.isVisibleChart() ) {
|
||||
//update earned value chart
|
||||
earnedValueChart.fillChart();
|
||||
|
||||
//update earned value legend
|
||||
updateEarnedValueChartLegend();
|
||||
}
|
||||
|
|
@ -591,31 +583,26 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
return result;
|
||||
}
|
||||
|
||||
void hookInto(EnumSet<ChangeTypes> reloadOn,
|
||||
IReloadChartListener reloadChart) {
|
||||
void hookInto(EnumSet<ChangeTypes> reloadOn, IReloadChartListener reloadChart) {
|
||||
Validate.notNull(reloadChart);
|
||||
hookIntoImpl(wrapIfNeeded(reloadChart), reloadOn);
|
||||
}
|
||||
|
||||
private IReloadChartListener wrapIfNeeded(
|
||||
IReloadChartListener reloadChart) {
|
||||
if (!wrapOnReadOnlyTransaction) {
|
||||
private IReloadChartListener wrapIfNeeded(IReloadChartListener reloadChart) {
|
||||
if ( !wrapOnReadOnlyTransaction ) {
|
||||
return reloadChart;
|
||||
}
|
||||
return AdHocTransactionService.readOnlyProxy(transactionService,
|
||||
IReloadChartListener.class, reloadChart);
|
||||
return AdHocTransactionService.readOnlyProxy(transactionService, IReloadChartListener.class, reloadChart);
|
||||
}
|
||||
|
||||
private void hookIntoImpl(IReloadChartListener reloadChart,
|
||||
EnumSet<ChangeTypes> reloadOn) {
|
||||
if (saveCommand != null
|
||||
&& reloadOn.contains(ChangeTypes.ON_GRAPH_CHANGED)) {
|
||||
private void hookIntoImpl(IReloadChartListener reloadChart, EnumSet<ChangeTypes> reloadOn) {
|
||||
if ( saveCommand != null && reloadOn.contains(ChangeTypes.ON_GRAPH_CHANGED) ) {
|
||||
hookIntoSaveCommand(reloadChart);
|
||||
}
|
||||
if (reloadOn.contains(ChangeTypes.ON_RELOAD_CHART_REQUESTED)) {
|
||||
if ( reloadOn.contains(ChangeTypes.ON_RELOAD_CHART_REQUESTED) ) {
|
||||
hookIntoReloadChartRequested(reloadChart);
|
||||
}
|
||||
if (reloadOn.contains(ChangeTypes.ON_GRAPH_CHANGED)) {
|
||||
if ( reloadOn.contains(ChangeTypes.ON_GRAPH_CHANGED) ) {
|
||||
hookIntoGraphChanged(reloadChart);
|
||||
}
|
||||
}
|
||||
|
|
@ -630,14 +617,12 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
saveCommand.addListener(afterSaveListener);
|
||||
}
|
||||
|
||||
private void hookIntoReloadChartRequested(
|
||||
IReloadChartListener reloadChart) {
|
||||
private void hookIntoReloadChartRequested(IReloadChartListener reloadChart) {
|
||||
configuration.addReloadChartListener(reloadChart);
|
||||
}
|
||||
|
||||
private void hookIntoGraphChanged(final IReloadChartListener reloadChart) {
|
||||
configuration
|
||||
.addPostGraphChangeListener(new IGraphChangeListener() {
|
||||
configuration.addPostGraphChangeListener(new IGraphChangeListener() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
|
@ -648,8 +633,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
}
|
||||
|
||||
private void addPrintSupport(
|
||||
PlannerConfiguration<TaskElement> configuration, final Order order) {
|
||||
private void addPrintSupport(PlannerConfiguration<TaskElement> configuration, final Order order) {
|
||||
configuration.setPrintAction(new IPrintAction() {
|
||||
@Override
|
||||
public void doPrint() {
|
||||
|
|
@ -662,8 +646,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doPrint(HashMap<String, String> parameters,
|
||||
Planner planner) {
|
||||
public void doPrint(HashMap<String, String> parameters, Planner planner) {
|
||||
CutyPrint.print(order, parameters, planner);
|
||||
|
||||
}
|
||||
|
|
@ -676,8 +659,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
return deleteMilestoneCommand;
|
||||
}
|
||||
|
||||
private void configureModificators(Order orderReloaded,
|
||||
PlannerConfiguration<TaskElement> configuration) {
|
||||
private void configureModificators(Order orderReloaded, PlannerConfiguration<TaskElement> configuration) {
|
||||
// Either InitDate or DeadLine must be set, depending on forwards or
|
||||
// backwards planning
|
||||
configuration.setSecondLevelModificators(SeveralModificators.create(
|
||||
|
|
@ -743,7 +725,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
private Tab createTab(String name, final String id) {
|
||||
Tab tab = new Tab(name);
|
||||
tab.setId(id);
|
||||
if (id.equals(tabSelected)) {
|
||||
if ( id.equals(tabSelected) ) {
|
||||
tab.setSelected(true);
|
||||
}
|
||||
tab.addEventListener("onClick", new EventListener() {
|
||||
|
|
@ -761,13 +743,11 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
hbox.setClass("legend-container");
|
||||
hbox.setAlign("center");
|
||||
hbox.setPack("center");
|
||||
Executions.createComponents("/planner/_legendLoadChartOrder.zul", hbox,
|
||||
null);
|
||||
Executions.createComponents("/planner/_legendLoadChartOrder.zul", hbox, null);
|
||||
return hbox;
|
||||
}
|
||||
|
||||
private Constraint dateMustBeInsideVisualizationArea(
|
||||
final OrderEarnedValueChartFiller earnedValueChartFiller) {
|
||||
private Constraint dateMustBeInsideVisualizationArea(final OrderEarnedValueChartFiller earnedValueChartFiller) {
|
||||
return new Constraint() {
|
||||
|
||||
@Override
|
||||
|
|
@ -775,13 +755,12 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
Object valueObject)
|
||||
throws WrongValueException {
|
||||
Date value = (Date) valueObject;
|
||||
if (value != null
|
||||
&& !EarnedValueChartFiller.includes(
|
||||
earnedValueChartFiller
|
||||
.getIndicatorsDefinitionInterval(), LocalDate
|
||||
.fromDateFields(value))) {
|
||||
throw new WrongValueException(comp,
|
||||
_("Date must be inside visualization area"));
|
||||
|
||||
if ( value != null && !EarnedValueChartFiller.includes(
|
||||
earnedValueChartFiller.getIndicatorsDefinitionInterval(),
|
||||
LocalDate.fromDateFields(value)) ) {
|
||||
|
||||
throw new WrongValueException(comp, _("Date must be inside visualization area"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -790,16 +769,15 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private void dateInfutureMessage(Datebox datebox) {
|
||||
Date value = datebox.getValue();
|
||||
Date today = LocalDate.fromDateFields(new Date())
|
||||
.toDateTimeAtStartOfDay().toDate();
|
||||
if (value != null && (value.compareTo(today) > 0)) {
|
||||
Date today = LocalDate.fromDateFields(new Date()).toDateTimeAtStartOfDay().toDate();
|
||||
if ( value != null && (value.compareTo(today) > 0) ) {
|
||||
throw new WrongValueException(datebox, _("date in the future"));
|
||||
}
|
||||
}
|
||||
|
||||
private void appendEventListenerToDateboxIndicators(
|
||||
final OrderEarnedValueChartFiller earnedValueChartFiller,
|
||||
final Vbox vbox) {
|
||||
private void appendEventListenerToDateboxIndicators(final OrderEarnedValueChartFiller earnedValueChartFiller,
|
||||
final Vbox vbox) {
|
||||
|
||||
earnedValueChartLegendDatebox.addEventListener(Events.ON_CHANGE,
|
||||
new EventListener() {
|
||||
|
||||
|
|
@ -816,33 +794,29 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
try {
|
||||
//force the validation again (getValue alone doesn't work because
|
||||
//the result of the validation is cached)
|
||||
earnedValueChartLegendDatebox.setValue(
|
||||
earnedValueChartLegendDatebox.getValue());
|
||||
earnedValueChartLegendDatebox.setValue(earnedValueChartLegendDatebox.getValue());
|
||||
}
|
||||
catch (WrongValueException e) {
|
||||
//the user moved the gantt and the legend became out of the
|
||||
//visualization area, reset to a correct date
|
||||
earnedValueChartLegendDatebox.setValue(earnedValueChartFiller.
|
||||
initialDateForIndicatorValues().toDateTimeAtStartOfDay()
|
||||
.toDate());
|
||||
earnedValueChartLegendDatebox.setValue(earnedValueChartFiller.initialDateForIndicatorValues().
|
||||
toDateTimeAtStartOfDay().toDate());
|
||||
}
|
||||
LocalDate date = new LocalDate(earnedValueChartLegendDatebox.getRawValue());
|
||||
org.zkoss.zk.ui.Component child = earnedValueChartLegendContainer
|
||||
.getFellow("indicatorsTable");
|
||||
org.zkoss.zk.ui.Component child = earnedValueChartLegendContainer.getFellow("indicatorsTable");
|
||||
updateEarnedValueChartLegend(date);
|
||||
}
|
||||
|
||||
private void updateEarnedValueChartLegend(LocalDate date) {
|
||||
for (EarnedValueType type : EarnedValueType.values()) {
|
||||
Label valueLabel = (Label) earnedValueChartLegendContainer
|
||||
.getFellow(type.toString());
|
||||
valueLabel.setValue(getLabelTextEarnedValueType(
|
||||
earnedValueChartFiller, type, date));
|
||||
Label valueLabel = (Label) earnedValueChartLegendContainer.getFellow(type.toString());
|
||||
valueLabel.setValue(getLabelTextEarnedValueType(earnedValueChartFiller, type, date));
|
||||
}
|
||||
}
|
||||
|
||||
private org.zkoss.zk.ui.Component getEarnedValueChartConfigurableLegend(
|
||||
OrderEarnedValueChartFiller earnedValueChartFiller, LocalDate date) {
|
||||
|
||||
Hbox mainhbox = new Hbox();
|
||||
mainhbox.setId("indicatorsTable");
|
||||
|
||||
|
|
@ -864,8 +838,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
checkbox.setAttribute("indicator", type);
|
||||
checkbox.setStyle("color: " + type.getColor());
|
||||
|
||||
Label valueLabel = new Label(getLabelTextEarnedValueType(
|
||||
earnedValueChartFiller, type, date));
|
||||
Label valueLabel = new Label(getLabelTextEarnedValueType(earnedValueChartFiller, type, date));
|
||||
valueLabel.setId(type.toString());
|
||||
|
||||
Hbox hbox = new Hbox();
|
||||
|
|
@ -874,9 +847,11 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
columnNumber = columnNumber + 1;
|
||||
switch (columnNumber) {
|
||||
|
||||
case 1:
|
||||
column1.appendChild(hbox);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
column2.appendChild(hbox);
|
||||
columnNumber = 0;
|
||||
|
|
@ -897,13 +872,12 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
return mainhbox;
|
||||
}
|
||||
|
||||
private String getLabelTextEarnedValueType(
|
||||
OrderEarnedValueChartFiller earnedValueChartFiller,
|
||||
EarnedValueType type, LocalDate date) {
|
||||
private String getLabelTextEarnedValueType(OrderEarnedValueChartFiller earnedValueChartFiller,
|
||||
EarnedValueType type, LocalDate date) {
|
||||
|
||||
BigDecimal value = earnedValueChartFiller.getIndicator(type, date);
|
||||
String units = _("h");
|
||||
if (type.equals(EarnedValueType.CPI)
|
||||
|| type.equals(EarnedValueType.SPI)) {
|
||||
if ( type.equals(EarnedValueType.CPI) || type.equals(EarnedValueType.SPI) ) {
|
||||
value = value.multiply(new BigDecimal(100));
|
||||
units = "%";
|
||||
}
|
||||
|
|
@ -912,11 +886,12 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private void markAsSelectedDefaultIndicators() {
|
||||
for (Checkbox checkbox : earnedValueChartConfigurationCheckboxes) {
|
||||
EarnedValueType type = (EarnedValueType) checkbox
|
||||
.getAttribute("indicator");
|
||||
EarnedValueType type = (EarnedValueType) checkbox.getAttribute("indicator");
|
||||
switch (type) {
|
||||
case BCWS:
|
||||
|
||||
case ACWP:
|
||||
|
||||
case BCWP:
|
||||
checkbox.setChecked(true);
|
||||
break;
|
||||
|
|
@ -931,17 +906,15 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
private Set<EarnedValueType> getEarnedValueSelectedIndicators() {
|
||||
Set<EarnedValueType> result = new HashSet<EarnedValueType>();
|
||||
for (Checkbox checkbox : earnedValueChartConfigurationCheckboxes) {
|
||||
if (checkbox.isChecked()) {
|
||||
EarnedValueType type = (EarnedValueType) checkbox
|
||||
.getAttribute("indicator");
|
||||
if ( checkbox.isChecked() ) {
|
||||
EarnedValueType type = (EarnedValueType) checkbox.getAttribute("indicator");
|
||||
result.add(type);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setEventListenerConfigurationCheckboxes(
|
||||
final Chart earnedValueChart) {
|
||||
private void setEventListenerConfigurationCheckboxes(final Chart earnedValueChart) {
|
||||
for (Checkbox checkbox : earnedValueChartConfigurationCheckboxes) {
|
||||
checkbox.addEventListener(Events.ON_CHECK, new EventListener() {
|
||||
|
||||
|
|
@ -962,25 +935,22 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
}
|
||||
}
|
||||
|
||||
private void refillLoadChartWhenNeeded(ChangeHooker changeHooker,
|
||||
final Planner planner, final Chart loadChart,
|
||||
final boolean updateEarnedValueChartLegend) {
|
||||
planner.getTimeTracker().addZoomListener(
|
||||
fillOnZoomChange(loadChart, planner, updateEarnedValueChartLegend));
|
||||
planner
|
||||
.addChartVisibilityListener(fillOnChartVisibilityChange(loadChart));
|
||||
private void refillLoadChartWhenNeeded(ChangeHooker changeHooker, final Planner planner, final Chart loadChart,
|
||||
final boolean updateEarnedValueChartLegend) {
|
||||
|
||||
changeHooker.withReadOnlyTransactionWraping().hookInto(
|
||||
EnumSet.allOf(ChangeTypes.class), new IReloadChartListener() {
|
||||
planner.getTimeTracker().addZoomListener(fillOnZoomChange(loadChart, planner, updateEarnedValueChartLegend));
|
||||
planner.addChartVisibilityListener(fillOnChartVisibilityChange(loadChart));
|
||||
|
||||
changeHooker.withReadOnlyTransactionWraping().hookInto(EnumSet.allOf(ChangeTypes.class), new IReloadChartListener() {
|
||||
|
||||
@Override
|
||||
public void reloadChart() {
|
||||
if (isExecutingOutsideZKExecution()) {
|
||||
if ( isExecutingOutsideZKExecution() ) {
|
||||
return;
|
||||
}
|
||||
if (planner.isVisibleChart()) {
|
||||
if ( planner.isVisibleChart() ) {
|
||||
loadChart.fillChart();
|
||||
if(updateEarnedValueChartLegend) {
|
||||
if( updateEarnedValueChartLegend ) {
|
||||
updateEarnedValueChartLegend();
|
||||
}
|
||||
}
|
||||
|
|
@ -993,20 +963,21 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
}
|
||||
|
||||
private void addAdditional(List<ICommand<TaskElement>> additional,
|
||||
PlannerConfiguration<TaskElement> configuration) {
|
||||
PlannerConfiguration<TaskElement> configuration) {
|
||||
|
||||
for (ICommand<TaskElement> c : additional) {
|
||||
configuration.addGlobalCommand(c);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWritingAllowedOnOrder() {
|
||||
if (planningState.getSavedOrderState() == OrderStatusEnum.STORED
|
||||
&& planningState.getOrder().getState() == OrderStatusEnum.STORED) {
|
||||
if ( planningState.getSavedOrderState() == OrderStatusEnum.STORED &&
|
||||
planningState.getOrder().getState() == OrderStatusEnum.STORED ) {
|
||||
|
||||
// STORED orders can't be saved, independently of user permissions
|
||||
return false;
|
||||
}
|
||||
if (SecurityUtils
|
||||
.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_ALL_PROJECTS)) {
|
||||
if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_ALL_PROJECTS) ) {
|
||||
return true;
|
||||
}
|
||||
return thereIsWriteAuthorizationFor(planningState.getOrder());
|
||||
|
|
@ -1016,9 +987,8 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
String loginName = SecurityUtils.getSessionUserLoginName();
|
||||
try {
|
||||
User user = userDAO.findByLoginName(loginName);
|
||||
for (OrderAuthorization authorization : orderAuthorizationDAO
|
||||
.listByOrderUserAndItsProfiles(order, user)) {
|
||||
if (authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) {
|
||||
for (OrderAuthorization authorization : orderAuthorizationDAO.listByOrderUserAndItsProfiles(order, user)) {
|
||||
if ( authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1364,8 +1334,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
}
|
||||
|
||||
private ISubcontractCommand buildSubcontractCommand(
|
||||
EditTaskController editTaskController) {
|
||||
private ISubcontractCommand buildSubcontractCommand(EditTaskController editTaskController) {
|
||||
subcontractCommand.initialize(editTaskController, planningState);
|
||||
return subcontractCommand;
|
||||
}
|
||||
|
|
@ -1390,7 +1359,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private void forceLoadLabels(OrderElement orderElement) {
|
||||
orderElement.getLabels().size();
|
||||
if (!orderElement.isLeaf()) {
|
||||
if ( !orderElement.isLeaf() ) {
|
||||
for (OrderElement element : orderElement.getChildren()) {
|
||||
forceLoadLabels(element);
|
||||
}
|
||||
|
|
@ -1403,7 +1372,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
hoursGroup.getCriterionRequirements().size();
|
||||
}
|
||||
|
||||
if (!orderElement.isLeaf()) {
|
||||
if ( !orderElement.isLeaf() ) {
|
||||
for (OrderElement element : orderElement.getChildren()) {
|
||||
forceLoadCriterionRequirements(element);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,32 +130,33 @@ public class SaveCommandBuilder {
|
|||
|
||||
private static final Log LOG = LogFactory.getLog(SaveCommandBuilder.class);
|
||||
|
||||
public ISaveCommand build(PlanningState planningState,
|
||||
PlannerConfiguration<TaskElement> plannerConfiguration) {
|
||||
SaveCommand result = new SaveCommand(planningState,
|
||||
plannerConfiguration);
|
||||
public ISaveCommand build(PlanningState planningState, PlannerConfiguration<TaskElement> plannerConfiguration) {
|
||||
SaveCommand result = new SaveCommand(planningState, plannerConfiguration);
|
||||
|
||||
return ConcurrentModificationHandling.addHandling(
|
||||
"/planner/index.zul;company_scheduling", ISaveCommand.class,
|
||||
result);
|
||||
"/planner/index.zul;company_scheduling", ISaveCommand.class, result);
|
||||
}
|
||||
|
||||
public static void dontPoseAsTransientAndChildrenObjects(
|
||||
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
|
||||
|
||||
for (ResourceAllocation<?> each : resourceAllocations) {
|
||||
each.dontPoseAsTransientObjectAnymore();
|
||||
each.makeAssignmentsContainersDontPoseAsTransientAnyMore();
|
||||
|
||||
for (DayAssignment eachAssignment : each.getAssignments()) {
|
||||
eachAssignment.dontPoseAsTransientObjectAnymore();
|
||||
}
|
||||
|
||||
for (DerivedAllocation eachDerived : each.getDerivedAllocations()) {
|
||||
eachDerived.dontPoseAsTransientObjectAnymore();
|
||||
Collection<DerivedDayAssignmentsContainer> containers = eachDerived
|
||||
.getContainers();
|
||||
Collection<DerivedDayAssignmentsContainer> containers = eachDerived.getContainers();
|
||||
|
||||
for (DerivedDayAssignmentsContainer eachContainer : containers) {
|
||||
eachContainer.dontPoseAsTransientObjectAnymore();
|
||||
}
|
||||
for (DerivedDayAssignment eachAssignment : eachDerived
|
||||
.getAssignments()) {
|
||||
|
||||
for (DerivedDayAssignment eachAssignment : eachDerived.getAssignments()) {
|
||||
eachAssignment.dontPoseAsTransientObjectAnymore();
|
||||
}
|
||||
}
|
||||
|
|
@ -164,13 +165,11 @@ public class SaveCommandBuilder {
|
|||
}
|
||||
|
||||
private static void dontPoseAsTransient(LimitingResourceQueueElement element) {
|
||||
if (element != null) {
|
||||
for (LimitingResourceQueueDependency d : element
|
||||
.getDependenciesAsOrigin()) {
|
||||
if ( element != null ) {
|
||||
for (LimitingResourceQueueDependency d : element.getDependenciesAsOrigin()) {
|
||||
d.dontPoseAsTransientObjectAnymore();
|
||||
}
|
||||
for (LimitingResourceQueueDependency d : element
|
||||
.getDependenciesAsDestiny()) {
|
||||
for (LimitingResourceQueueDependency d : element.getDependenciesAsDestiny()) {
|
||||
d.dontPoseAsTransientObjectAnymore();
|
||||
}
|
||||
element.dontPoseAsTransientObjectAnymore();
|
||||
|
|
@ -236,31 +235,27 @@ public class SaveCommandBuilder {
|
|||
|
||||
private boolean disabled = false;
|
||||
|
||||
public SaveCommand(PlanningState planningState,
|
||||
PlannerConfiguration<TaskElement> configuration) {
|
||||
public SaveCommand(PlanningState planningState, PlannerConfiguration<TaskElement> configuration) {
|
||||
this.state = planningState;
|
||||
this.configuration = configuration;
|
||||
this.adapter = configuration.getAdapter();
|
||||
this.constraintCalculator = new ConstraintCalculator<TaskElement>(
|
||||
configuration.isScheduleBackwards()) {
|
||||
this.constraintCalculator = new ConstraintCalculator<TaskElement>(configuration.isScheduleBackwards()) {
|
||||
|
||||
@Override
|
||||
protected GanttDate getStartDate(TaskElement vertex) {
|
||||
return TaskElementAdapter.toGantt(vertex
|
||||
.getIntraDayStartDate());
|
||||
return TaskElementAdapter.toGantt(vertex.getIntraDayStartDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GanttDate getEndDate(TaskElement vertex) {
|
||||
return TaskElementAdapter.toGantt(vertex
|
||||
.getIntraDayEndDate());
|
||||
return TaskElementAdapter.toGantt(vertex.getIntraDayEndDate());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContext<TaskElement> context) {
|
||||
if (disabled) {
|
||||
if ( disabled ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -269,7 +264,7 @@ public class SaveCommandBuilder {
|
|||
@Override
|
||||
public void doActions() {
|
||||
// A little bit hack
|
||||
if (taskPropertiesController != null)
|
||||
if ( taskPropertiesController != null )
|
||||
taskPropertiesController.emailNotificationAddNew();
|
||||
|
||||
notifyUserThatSavingIsDone();
|
||||
|
|
@ -289,44 +284,39 @@ public class SaveCommandBuilder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void save(final IBeforeSaveActions beforeSaveActions,
|
||||
IAfterSaveActions afterSaveActions) {
|
||||
public void save(final IBeforeSaveActions beforeSaveActions, IAfterSaveActions afterSaveActions) {
|
||||
try {
|
||||
if (state.getScenarioInfo().isUsingTheOwnerScenario()
|
||||
|| userAcceptsCreateANewOrderVersion()) {
|
||||
transactionService
|
||||
.runOnTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
if (beforeSaveActions != null) {
|
||||
beforeSaveActions.doActions();
|
||||
}
|
||||
doTheSaving();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if ( state.getScenarioInfo().isUsingTheOwnerScenario() || userAcceptsCreateANewOrderVersion() ) {
|
||||
transactionService.runOnTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
if (beforeSaveActions != null) {
|
||||
beforeSaveActions.doActions();
|
||||
}
|
||||
doTheSaving();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
dontPoseAsTransientObjectAnymore(state.getOrder());
|
||||
dontPoseAsTransientObjectAnymore(state.getOrder()
|
||||
.getEndDateCommunicationToCustomer());
|
||||
dontPoseAsTransientObjectAnymore(state.getOrder().getEndDateCommunicationToCustomer());
|
||||
state.getScenarioInfo().afterCommit();
|
||||
|
||||
if (state.getOrder()
|
||||
.isNeededToRecalculateSumChargedEfforts()) {
|
||||
sumChargedEffortRecalculator.recalculate(state
|
||||
.getOrder().getId());
|
||||
if ( state.getOrder().isNeededToRecalculateSumChargedEfforts() ) {
|
||||
sumChargedEffortRecalculator.recalculate(state.getOrder().getId());
|
||||
}
|
||||
|
||||
if (state.getOrder().isNeededToRecalculateSumExpenses()) {
|
||||
if ( state.getOrder().isNeededToRecalculateSumExpenses() ) {
|
||||
sumExpensesRecalculator.recalculate(state.getOrder().getId());
|
||||
}
|
||||
|
||||
fireAfterSave();
|
||||
if (afterSaveActions != null) {
|
||||
if ( afterSaveActions != null ) {
|
||||
afterSaveActions.doActions();
|
||||
}
|
||||
}
|
||||
} catch (ValidationException validationException) {
|
||||
if (Executions.getCurrent() == null) {
|
||||
if ( Executions.getCurrent() == null ) {
|
||||
throw validationException;
|
||||
}
|
||||
|
||||
|
|
@ -334,22 +324,21 @@ public class SaveCommandBuilder {
|
|||
String message = "";
|
||||
|
||||
LabelCreatorForInvalidValues labelCreator = new LabelCreatorForInvalidValues();
|
||||
for (InvalidValue invalidValue : validationException
|
||||
.getInvalidValues()) {
|
||||
message += "* "
|
||||
+ ((Label) labelCreator
|
||||
.createLabelFor(invalidValue))
|
||||
.getValue() + "\n";
|
||||
|
||||
for (InvalidValue invalidValue : validationException.getInvalidValues()) {
|
||||
message += "* " + ((Label) labelCreator.createLabelFor(invalidValue)).getValue() + "\n";
|
||||
}
|
||||
|
||||
if (validationException.getInvalidValues().isEmpty()) {
|
||||
if ( validationException.getInvalidValues().isEmpty() ) {
|
||||
message += validationException.getMessage();
|
||||
}
|
||||
|
||||
LOG.warn("Error saving the project", validationException);
|
||||
|
||||
Messagebox.show(
|
||||
_("Error saving the project\n{0}", message),
|
||||
_("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -364,23 +353,20 @@ public class SaveCommandBuilder {
|
|||
}
|
||||
|
||||
private void notifyUserThatSavingIsDone() {
|
||||
if (Executions.getCurrent() == null) {
|
||||
if ( Executions.getCurrent() == null ) {
|
||||
// test environment
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Messagebox.show(_("Project saved"), _("Information"),
|
||||
Messagebox.OK, Messagebox.INFORMATION);
|
||||
Messagebox.show(_("Project saved"), _("Information"), Messagebox.OK, Messagebox.INFORMATION);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (Executions.getCurrent() != null) {
|
||||
if ( Executions.getCurrent() != null ) {
|
||||
// Reset timer of warning on leaving page
|
||||
ConfirmCloseUtil.resetConfirmClose();
|
||||
if (SecurityUtils.loggedUserCanWrite(state.getOrder())) {
|
||||
ConfirmCloseUtil
|
||||
.setConfirmClose(
|
||||
Executions.getCurrent().getDesktop(),
|
||||
if ( SecurityUtils.loggedUserCanWrite(state.getOrder()) ) {
|
||||
ConfirmCloseUtil.setConfirmClose(Executions.getCurrent().getDesktop(),
|
||||
_("You are about to leave the planning editing. Unsaved changes will be lost!"));
|
||||
}
|
||||
}
|
||||
|
|
@ -398,7 +384,7 @@ public class SaveCommandBuilder {
|
|||
|
||||
TaskGroup rootTask = state.getRootTask();
|
||||
|
||||
if (rootTask != null) {
|
||||
if ( rootTask != null ) {
|
||||
// This reattachment is needed to ensure that the root task in
|
||||
// the state is the one associated to the transaction's session.
|
||||
// Otherwise if some order element has been removed, when doing
|
||||
|
|
@ -416,7 +402,7 @@ public class SaveCommandBuilder {
|
|||
removeTasksToRemove();
|
||||
loadDataAccessedWithNotPosedAsTransientInOrder(state.getOrder());
|
||||
loadDataAccessedWithNotPosedAsTransient(state.getOrder());
|
||||
if (state.getRootTask() != null) {
|
||||
if ( state.getRootTask() != null ) {
|
||||
loadDependenciesCollectionsForTaskRoot(state.getRootTask());
|
||||
}
|
||||
subcontractedTaskDataDAO.removeOrphanedSubcontractedTaskData();
|
||||
|
|
@ -1064,16 +1050,15 @@ public class SaveCommandBuilder {
|
|||
@Override
|
||||
public org.zkoss.zk.ui.Component createLabelFor(
|
||||
InvalidValue invalidValue) {
|
||||
if (invalidValue.getRootBean() instanceof OrderElement) {
|
||||
if ( invalidValue.getRootBean() instanceof OrderElement ) {
|
||||
Label result = new Label();
|
||||
|
||||
String orderElementName;
|
||||
if (invalidValue.getRootBean() instanceof Order) {
|
||||
if ( invalidValue.getRootBean() instanceof Order ) {
|
||||
orderElementName = _("Project");
|
||||
} else {
|
||||
orderElementName = _("Task {0}",
|
||||
((OrderElement) invalidValue.getRootBean())
|
||||
.getName());
|
||||
((OrderElement) invalidValue.getRootBean()).getName());
|
||||
}
|
||||
|
||||
result.setValue(orderElementName + ": "
|
||||
|
|
|
|||
|
|
@ -133,14 +133,15 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
return subcontractController;
|
||||
}
|
||||
|
||||
private void showEditForm(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement, PlanningState planningState) {
|
||||
private void showEditForm(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement,
|
||||
PlanningState planningState) {
|
||||
|
||||
showEditForm(context, taskElement, planningState, false);
|
||||
}
|
||||
|
||||
private void showEditForm(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement, PlanningState planningState,
|
||||
boolean fromLimitingResourcesView) {
|
||||
private void showEditForm(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement,
|
||||
PlanningState planningState, boolean fromLimitingResourcesView) {
|
||||
|
||||
this.taskElement = taskElement;
|
||||
this.context = context;
|
||||
this.planningState = planningState;
|
||||
|
|
@ -152,7 +153,7 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
showSelectedTabPanel();
|
||||
Util.createBindingsFor(window);
|
||||
Util.reloadBindings(window);
|
||||
if (fromLimitingResourcesView) {
|
||||
if ( fromLimitingResourcesView ) {
|
||||
window.doModal();
|
||||
} else {
|
||||
window.setMode("modal");
|
||||
|
|
@ -163,30 +164,22 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
private void showSelectedTabPanel() {
|
||||
showTabPanel(taskPropertiesController
|
||||
.getResourceAllocationType(taskElement));
|
||||
showTabPanel(taskPropertiesController.getResourceAllocationType(taskElement));
|
||||
}
|
||||
|
||||
public void showTabPanel(
|
||||
ResourceAllocationTypeEnum resourceAllocationType) {
|
||||
public void showTabPanel(ResourceAllocationTypeEnum resourceAllocationType) {
|
||||
subcontractTab.setVisible(false);
|
||||
resourceAllocationTab.setVisible(false);
|
||||
limitingResourceAllocationTab.setVisible(false);
|
||||
|
||||
if (ResourceAllocationTypeEnum.SUBCONTRACT
|
||||
.equals(resourceAllocationType)) {
|
||||
|
||||
subcontractController.init(asTask(taskElement), context,
|
||||
taskPropertiesController.getTaskEditFormComposer());
|
||||
if ( ResourceAllocationTypeEnum.SUBCONTRACT.equals(resourceAllocationType) ) {
|
||||
subcontractController.init(asTask(taskElement), context, taskPropertiesController.getTaskEditFormComposer());
|
||||
showSubcontractTab();
|
||||
} else if (ResourceAllocationTypeEnum.NON_LIMITING_RESOURCES
|
||||
.equals(resourceAllocationType)) {
|
||||
} else if ( ResourceAllocationTypeEnum.NON_LIMITING_RESOURCES.equals(resourceAllocationType) ) {
|
||||
resourceAllocationController.init(context, asTask(taskElement), planningState, messagesForUser);
|
||||
showNonLimitingResourcesTab();
|
||||
} else if (ResourceAllocationTypeEnum.LIMITING_RESOURCES
|
||||
.equals(resourceAllocationType)) {
|
||||
limitingResourceAllocationController.init(context, asTask(taskElement),
|
||||
planningState, messagesForUser);
|
||||
} else if ( ResourceAllocationTypeEnum.LIMITING_RESOURCES.equals(resourceAllocationType) ) {
|
||||
limitingResourceAllocationController.init(context, asTask(taskElement), planningState, messagesForUser);
|
||||
showLimitingResourcesTab();
|
||||
}
|
||||
}
|
||||
|
|
@ -205,9 +198,9 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
limitingResourceAllocationTab.setVisible(true);
|
||||
}
|
||||
|
||||
public void showEditFormTaskProperties(
|
||||
IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement, PlanningState planningState) {
|
||||
public void showEditFormTaskProperties(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement,
|
||||
PlanningState planningState) {
|
||||
|
||||
editTaskTabbox.setSelectedPanelApi(taskPropertiesTabpanel);
|
||||
showEditForm(context, taskElement, planningState);
|
||||
}
|
||||
|
|
@ -218,21 +211,17 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
showEditFormResourceAllocation(null, taskElement, null, true);
|
||||
}
|
||||
|
||||
public void showEditFormResourceAllocation(
|
||||
IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement, PlanningState planningState) {
|
||||
showEditFormResourceAllocation(context, taskElement, planningState,
|
||||
false);
|
||||
public void showEditFormResourceAllocation(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement,
|
||||
PlanningState planningState) {
|
||||
showEditFormResourceAllocation(context, taskElement, planningState, false);
|
||||
}
|
||||
|
||||
public void showEditFormResourceAllocation(
|
||||
IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement, PlanningState planningState,
|
||||
boolean fromLimitingResourcesView) {
|
||||
public void showEditFormResourceAllocation(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement,
|
||||
PlanningState planningState, boolean fromLimitingResourcesView) {
|
||||
|
||||
if (isTask(taskElement)) {
|
||||
if ( isTask(taskElement) ) {
|
||||
Task task = asTask(taskElement);
|
||||
if (task.isLimiting()) {
|
||||
if ( task.isLimiting() ) {
|
||||
editTaskTabbox.setSelectedPanelApi(limitingResourceAllocationTabpanel);
|
||||
} else {
|
||||
editTaskTabbox.setSelectedPanelApi(resourceAllocationTabpanel);
|
||||
|
|
@ -240,18 +229,17 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
} else {
|
||||
editTaskTabbox.setSelectedPanelApi(taskPropertiesTabpanel);
|
||||
}
|
||||
showEditForm(context, taskElement, planningState,
|
||||
fromLimitingResourcesView);
|
||||
showEditForm(context, taskElement, planningState, fromLimitingResourcesView);
|
||||
}
|
||||
|
||||
public void selectAssignmentTab(int index) {
|
||||
editTaskTabbox.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
public void showEditFormSubcontract(
|
||||
IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement, PlanningState planningState) {
|
||||
if (isSubcontractedAndIsTask(taskElement)) {
|
||||
public void showEditFormSubcontract(IContextWithPlannerTask<TaskElement> context, TaskElement taskElement,
|
||||
PlanningState planningState) {
|
||||
|
||||
if ( isSubcontractedAndIsTask(taskElement) ) {
|
||||
editTaskTabbox.setSelectedPanelApi(subcontractTabpanel);
|
||||
} else {
|
||||
editTaskTabbox.setSelectedPanelApi(taskPropertiesTabpanel);
|
||||
|
|
@ -261,7 +249,7 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
|
||||
public void accept() {
|
||||
try {
|
||||
if (taskPropertiesController.stateHasChanged()) {
|
||||
if ( taskPropertiesController.stateHasChanged() ) {
|
||||
ResourceAllocationTypeEnum oldState = taskPropertiesController.getOriginalState();
|
||||
removeAssociatedData(oldState);
|
||||
}
|
||||
|
|
@ -270,16 +258,16 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
taskPropertiesController.accept();
|
||||
|
||||
ResourceAllocationTypeEnum currentState = taskPropertiesController.getCurrentState();
|
||||
if (ResourceAllocationTypeEnum.NON_LIMITING_RESOURCES.equals(currentState)) {
|
||||
if ( ResourceAllocationTypeEnum.NON_LIMITING_RESOURCES.equals(currentState) ) {
|
||||
editTaskTabbox.setSelectedPanelApi(resourceAllocationTabpanel);
|
||||
boolean mustNotExit = !resourceAllocationController.accept();
|
||||
if (mustNotExit) {
|
||||
if ( mustNotExit ) {
|
||||
return;
|
||||
}
|
||||
} else if (ResourceAllocationTypeEnum.SUBCONTRACT.equals(currentState)) {
|
||||
} else if ( ResourceAllocationTypeEnum.SUBCONTRACT.equals(currentState) ) {
|
||||
editTaskTabbox.setSelectedPanelApi(subcontractTabpanel);
|
||||
subcontractController.accept();
|
||||
} else if (ResourceAllocationTypeEnum.LIMITING_RESOURCES.equals(currentState)) {
|
||||
} else if ( ResourceAllocationTypeEnum.LIMITING_RESOURCES.equals(currentState) ) {
|
||||
editTaskTabbox.setSelectedPanelApi(limitingResourceAllocationTabpanel);
|
||||
limitingResourceAllocationController.accept();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ public class TaskPropertiesController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public ResourceAllocationTypeEnum getResourceAllocationType(TaskElement taskElement) {
|
||||
if (taskElement == null || !isTask(taskElement)) {
|
||||
if ( taskElement == null || !isTask(taskElement) ) {
|
||||
return null;
|
||||
}
|
||||
return getResourceAllocationType(asTask(currentTaskElement));
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements
|
|||
@Transactional(readOnly = true)
|
||||
public void prepareForEdit(Worker worker) {
|
||||
this.worker = worker;
|
||||
if (worker != null) {
|
||||
if ( worker != null ) {
|
||||
reattachmentWorker();
|
||||
initDTOs();
|
||||
}
|
||||
|
|
@ -100,11 +100,9 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements
|
|||
|
||||
private void initDTOs() {
|
||||
criterionSatisfactionDTOs = new HashSet<CriterionSatisfactionDTO>();
|
||||
for (CriterionSatisfaction criterionSatisfaction : worker
|
||||
.getCriterionSatisfactions()) {
|
||||
if (!criterionSatisfaction.isIsDeleted()) {
|
||||
CriterionSatisfactionDTO dto = new CriterionSatisfactionDTO(
|
||||
criterionSatisfaction);
|
||||
for (CriterionSatisfaction criterionSatisfaction : worker.getCriterionSatisfactions()) {
|
||||
if ( !criterionSatisfaction.isIsDeleted() ) {
|
||||
CriterionSatisfactionDTO dto = new CriterionSatisfactionDTO(criterionSatisfaction);
|
||||
criterionSatisfactionDTOs.add(dto);
|
||||
}
|
||||
}
|
||||
|
|
@ -344,32 +342,32 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements
|
|||
}
|
||||
|
||||
private List<CriterionSatisfactionDTO> getWithCriterionAssignedDTOs() {
|
||||
return CriterionSatisfactionDTO
|
||||
.keepHavingCriterion(criterionSatisfactionDTOs);
|
||||
return CriterionSatisfactionDTO.keepHavingCriterion(criterionSatisfactionDTOs);
|
||||
}
|
||||
|
||||
private void updateDTOs() throws ValidationException, IllegalStateException {
|
||||
// Create a new list of Criterion satisfaction
|
||||
Set<CriterionSatisfaction> newList = new HashSet<CriterionSatisfaction>();
|
||||
|
||||
for (CriterionSatisfactionDTO satisfactionDTO : getWithCriterionAssignedDTOs()) {
|
||||
CriterionSatisfaction satisfaction;
|
||||
if (satisfactionDTO.isNewObject()) {
|
||||
Criterion criterion = satisfactionDTO.getCriterionWithItsType()
|
||||
.getCriterion();
|
||||
|
||||
if ( satisfactionDTO.isNewObject() ) {
|
||||
Criterion criterion = satisfactionDTO.getCriterionWithItsType().getCriterion();
|
||||
Interval interval = satisfactionDTO.getInterval();
|
||||
satisfaction = CriterionSatisfaction.create(criterion, worker,
|
||||
interval);
|
||||
satisfaction = CriterionSatisfaction.create(criterion, worker, interval);
|
||||
|
||||
// set the autogenerated code
|
||||
currentCriterionSatisfaction = satisfaction;
|
||||
setDefaultCode();
|
||||
} else {
|
||||
satisfaction = satisfactionDTO.getCriterionSatisfaction();
|
||||
if (satisfactionDTO.isIsDeleted()) {
|
||||
if ( satisfactionDTO.isIsDeleted() ) {
|
||||
satisfaction.setIsDeleted(true);
|
||||
} else {
|
||||
satisfaction.setStartDate(satisfactionDTO.getStart());
|
||||
if (satisfactionDTO.getEndDate() != null) {
|
||||
|
||||
if ( satisfactionDTO.getEndDate() != null ) {
|
||||
satisfaction.finish(satisfactionDTO.getEnd());
|
||||
} else {
|
||||
satisfaction.noFinish();
|
||||
|
|
|
|||
|
|
@ -72,21 +72,21 @@ public class WorkRelationshipsController extends GenericForwardComposer {
|
|||
private final IMessagesForUser messagesForUser;
|
||||
|
||||
public WorkRelationshipsController(IWorkerModel workerModel,
|
||||
WorkerCRUDController workerCRUDController,
|
||||
IMessagesForUser messagesForUser) {
|
||||
WorkerCRUDController workerCRUDController,
|
||||
IMessagesForUser messagesForUser) {
|
||||
|
||||
this.workerModel = workerModel;
|
||||
this.workerCRUDController = workerCRUDController;
|
||||
this.messagesForUser = messagesForUser;
|
||||
this.workCriterions = new ArrayList<Criterion>();
|
||||
Map<ICriterionType<?>, Collection<Criterion>> map = workerModel
|
||||
.getLaboralRelatedCriterions();
|
||||
Map<ICriterionType<?>, Collection<Criterion>> map = workerModel.getLaboralRelatedCriterions();
|
||||
this.fromCriterionToType = new HashMap<Criterion, CriterionWithItsType>();
|
||||
for (Entry<ICriterionType<?>, Collection<Criterion>> entry : map
|
||||
.entrySet()) {
|
||||
|
||||
for (Entry<ICriterionType<?>, Collection<Criterion>> entry : map.entrySet()) {
|
||||
this.workCriterions.addAll(entry.getValue());
|
||||
|
||||
for (Criterion criterion : entry.getValue()) {
|
||||
this.fromCriterionToType.put(criterion,
|
||||
new CriterionWithItsType(entry.getKey(), criterion));
|
||||
this.fromCriterionToType.put(criterion, new CriterionWithItsType(entry.getKey(), criterion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,8 +103,7 @@ import org.zkoss.zul.api.Window;
|
|||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
public class WorkerCRUDController extends GenericForwardComposer implements
|
||||
IWorkerCRUDControllerEntryPoints {
|
||||
public class WorkerCRUDController extends GenericForwardComposer implements IWorkerCRUDControllerEntryPoints {
|
||||
|
||||
@Autowired
|
||||
private IDBPasswordEncoderService dbPasswordEncoderService;
|
||||
|
|
@ -247,7 +246,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
if (save()) {
|
||||
if ( save() ) {
|
||||
goToList();
|
||||
}
|
||||
}
|
||||
|
|
@ -268,22 +267,22 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
setUserBindingInfo();
|
||||
|
||||
// Validate 'Cost category assignment' tab is correct
|
||||
if (resourcesCostCategoryAssignmentController != null) {
|
||||
if (!resourcesCostCategoryAssignmentController.validate()) {
|
||||
if ( resourcesCostCategoryAssignmentController != null ) {
|
||||
if ( !resourcesCostCategoryAssignmentController.validate() ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (baseCalendarEditionController != null) {
|
||||
if ( baseCalendarEditionController != null ) {
|
||||
baseCalendarEditionController.save();
|
||||
}
|
||||
if (criterionsController != null){
|
||||
if(!criterionsController.validate()){
|
||||
if ( criterionsController != null ){
|
||||
if( !criterionsController.validate() ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (workerModel.getCalendar() == null) {
|
||||
if ( workerModel.getCalendar() == null ) {
|
||||
createCalendar();
|
||||
}
|
||||
workerModel.save();
|
||||
|
|
@ -298,28 +297,26 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
private void setUserBindingInfo() {
|
||||
int option = userBindingRadiogroup.getSelectedIndex();
|
||||
|
||||
if (UserBindingOption.NOT_BOUND.ordinal() == option) {
|
||||
if ( UserBindingOption.NOT_BOUND.ordinal() == option ) {
|
||||
getWorker().setUser(null);
|
||||
}
|
||||
|
||||
if (UserBindingOption.EXISTING_USER.ordinal() == option) {
|
||||
if (getWorker().getUser() == null) {
|
||||
throw new WrongValueException(userBandbox,
|
||||
_("please select a user to bound"));
|
||||
if ( UserBindingOption.EXISTING_USER.ordinal() == option ) {
|
||||
if ( getWorker().getUser() == null ) {
|
||||
throw new WrongValueException(userBandbox, _("please select a user to bound"));
|
||||
}
|
||||
getWorker().updateUserData();
|
||||
}
|
||||
|
||||
if (UserBindingOption.CREATE_NEW_USER.ordinal() == option) {
|
||||
if ( UserBindingOption.CREATE_NEW_USER.ordinal() == option ) {
|
||||
getWorker().setUser(createNewUserForBinding());
|
||||
}
|
||||
}
|
||||
|
||||
private User createNewUserForBinding() {
|
||||
String loginName = loginNameTextbox.getValue();
|
||||
if (StringUtils.isBlank(loginName)) {
|
||||
throw new WrongValueException(loginNameTextbox,
|
||||
_("cannot be empty"));
|
||||
if ( StringUtils.isBlank(loginName) ) {
|
||||
throw new WrongValueException(loginNameTextbox, _("cannot be empty"));
|
||||
}
|
||||
|
||||
String password = passwordTextbox.getValue();
|
||||
|
|
@ -394,17 +391,15 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
state = CRUDControllerState.EDIT;
|
||||
getBookmarker().goToEditForm(worker);
|
||||
workerModel.prepareEditFor(worker);
|
||||
resourcesCostCategoryAssignmentController.setResource(workerModel
|
||||
.getWorker());
|
||||
if (isCalendarNotNull()) {
|
||||
resourcesCostCategoryAssignmentController.setResource(workerModel.getWorker());
|
||||
if ( isCalendarNotNull() ) {
|
||||
editCalendar();
|
||||
}
|
||||
editAsignedCriterions();
|
||||
updateUserBindingComponents();
|
||||
showEditWindow(_("Edit Worker: {0}", worker.getHumanId()));
|
||||
|
||||
Textbox workerFirstname = (Textbox) editWindow
|
||||
.getFellow("workerFirstname");
|
||||
Textbox workerFirstname = (Textbox) editWindow.getFellow("workerFirstname");
|
||||
workerFirstname.focus();
|
||||
}
|
||||
|
||||
|
|
@ -453,13 +448,11 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
getBookmarker().goToCreateForm();
|
||||
workerModel.prepareForCreate();
|
||||
createAsignedCriterions();
|
||||
resourcesCostCategoryAssignmentController.setResource(workerModel
|
||||
.getWorker());
|
||||
resourcesCostCategoryAssignmentController.setResource(workerModel.getWorker());
|
||||
updateUserBindingComponents();
|
||||
showEditWindow(_("Create Worker"));
|
||||
resourceCalendarModel.cancel();
|
||||
Textbox workerFirstname = (Textbox) editWindow
|
||||
.getFellow("workerFirstname");
|
||||
Textbox workerFirstname = (Textbox) editWindow.getFellow("workerFirstname");
|
||||
workerFirstname.focus();
|
||||
}
|
||||
|
||||
|
|
@ -473,12 +466,10 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
localizationsForEditionController = createLocalizationsController(comp,
|
||||
"editWindow");
|
||||
localizationsForCreationController = createLocalizationsController(
|
||||
comp, "editWindow");
|
||||
localizationsForEditionController = createLocalizationsController(comp, "editWindow");
|
||||
localizationsForCreationController = createLocalizationsController(comp, "editWindow");
|
||||
comp.setVariable("controller", this, true);
|
||||
if (messagesContainer == null) {
|
||||
if ( messagesContainer == null ) {
|
||||
throw new RuntimeException(_("MessagesContainer is needed"));
|
||||
}
|
||||
messages = new MessagesForUser(messagesContainer);
|
||||
|
|
@ -490,22 +481,20 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
initializeTabs();
|
||||
initUserBindingComponents();
|
||||
|
||||
final EntryPointsHandler<IWorkerCRUDControllerEntryPoints> handler = URLHandlerRegistry
|
||||
.getRedirectorFor(IWorkerCRUDControllerEntryPoints.class);
|
||||
final EntryPointsHandler<IWorkerCRUDControllerEntryPoints> handler =
|
||||
URLHandlerRegistry.getRedirectorFor(IWorkerCRUDControllerEntryPoints.class);
|
||||
|
||||
handler.register(this, page);
|
||||
}
|
||||
|
||||
private void initUserBindingComponents() {
|
||||
userBindingGroupbox = (Groupbox) editWindow
|
||||
.getFellowIfAny("userBindingGroupbox");
|
||||
userBindingRadiogroup = (Radiogroup) editWindow
|
||||
.getFellowIfAny("userBindingRadiogroup");
|
||||
userBindingGroupbox = (Groupbox) editWindow.getFellowIfAny("userBindingGroupbox");
|
||||
userBindingRadiogroup = (Radiogroup) editWindow.getFellowIfAny("userBindingRadiogroup");
|
||||
initUserBindingOptions();
|
||||
userBandbox = (BandboxSearch) editWindow.getFellowIfAny("userBandbox");
|
||||
loginNameTextbox = (Textbox) editWindow.getFellowIfAny("loginName");
|
||||
passwordTextbox = (Textbox) editWindow.getFellowIfAny("password");
|
||||
passwordConfirmationTextbox = (Textbox) editWindow
|
||||
.getFellowIfAny("passwordConfirmation");
|
||||
passwordConfirmationTextbox = (Textbox) editWindow.getFellowIfAny("passwordConfirmation");
|
||||
emailTextbox = (Textbox) editWindow.getFellowIfAny("email");
|
||||
}
|
||||
|
||||
|
|
@ -513,9 +502,10 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
UserBindingOption[] values = UserBindingOption.values();
|
||||
for (UserBindingOption option : values) {
|
||||
Radio radio = new Radio(_(option.label));
|
||||
if (option.equals(UserBindingOption.CREATE_NEW_USER)
|
||||
&& !SecurityUtils
|
||||
.isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS)) {
|
||||
|
||||
if ( option.equals(UserBindingOption.CREATE_NEW_USER) &&
|
||||
!SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS)) {
|
||||
|
||||
radio.setDisabled(true);
|
||||
radio.setTooltiptext(_("You do not have permissions to create new users"));
|
||||
}
|
||||
|
|
@ -530,14 +520,10 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
}
|
||||
|
||||
private void initFilterComponent() {
|
||||
this.filterFinishDate = (Datebox) listWindow
|
||||
.getFellowIfAny("filterFinishDate");
|
||||
this.filterStartDate = (Datebox) listWindow
|
||||
.getFellowIfAny("filterStartDate");
|
||||
this.filterLimitingResource = (Listbox) listWindow
|
||||
.getFellowIfAny("filterLimitingResource");
|
||||
this.bdFilters = (BandboxMultipleSearch) listWindow
|
||||
.getFellowIfAny("bdFilters");
|
||||
this.filterFinishDate = (Datebox) listWindow.getFellowIfAny("filterFinishDate");
|
||||
this.filterStartDate = (Datebox) listWindow.getFellowIfAny("filterStartDate");
|
||||
this.filterLimitingResource = (Listbox) listWindow.getFellowIfAny("filterLimitingResource");
|
||||
this.bdFilters = (BandboxMultipleSearch) listWindow.getFellowIfAny("bdFilters");
|
||||
this.txtfilter = (Textbox) listWindow.getFellowIfAny("txtfilter");
|
||||
this.listing = (Grid) listWindow.getFellowIfAny("listing");
|
||||
clearFilterDates();
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ import org.libreplan.business.planner.daos.IDayAssignmentDAO;
|
|||
import org.libreplan.business.planner.daos.IResourceAllocationDAO;
|
||||
import org.libreplan.business.resources.daos.ICriterionDAO;
|
||||
import org.libreplan.business.resources.daos.IResourceDAO;
|
||||
import org.libreplan.business.resources.daos.IWorkerDAO;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.CriterionSatisfaction;
|
||||
import org.libreplan.business.resources.entities.CriterionWithItsType;
|
||||
|
|
@ -152,21 +151,20 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
removeCalendarIfNeeded();
|
||||
resetRoleInOriginalBoundUser();
|
||||
resourceDAO.save(worker);
|
||||
if (worker.getCalendar() != null) {
|
||||
if ( worker.getCalendar() != null ) {
|
||||
baseCalendarModel.checkInvalidValuesCalendar(worker.getCalendar());
|
||||
}
|
||||
getLocalizationsAssigner().applyChanges();
|
||||
if(assignedCriterionsModel != null){
|
||||
if( assignedCriterionsModel != null ){
|
||||
assignedCriterionsModel.confirm();
|
||||
}
|
||||
localizationsAssigner = null;
|
||||
}
|
||||
|
||||
private void resetRoleInOriginalBoundUser() {
|
||||
if (boundUser != null) {
|
||||
if ( boundUser != null ) {
|
||||
User user = worker.getUser();
|
||||
if (user == null || user.getId() == null
|
||||
|| !user.getId().equals(boundUser.getId())) {
|
||||
if ( user == null || user.getId() == null || !user.getId().equals(boundUser.getId()) ) {
|
||||
boundUser.removeRole(UserRole.ROLE_BOUND_USER);
|
||||
userDAO.save(boundUser);
|
||||
}
|
||||
|
|
@ -174,7 +172,7 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
}
|
||||
|
||||
private void removeCalendarIfNeeded() {
|
||||
if (calendarToRemove != null) {
|
||||
if ( calendarToRemove != null ) {
|
||||
try {
|
||||
resourceDAO.reattach(worker);
|
||||
baseCalendarDAO.remove(calendarToRemove.getId());
|
||||
|
|
@ -224,19 +222,19 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
@Transactional(readOnly = true)
|
||||
public void prepareForCreate(boolean virtual) {
|
||||
|
||||
if (virtual) {
|
||||
if ( virtual ) {
|
||||
worker = VirtualWorker.create("");
|
||||
} else {
|
||||
worker = Worker.create("");
|
||||
}
|
||||
|
||||
worker.setCodeAutogenerated(configurationDAO.getConfiguration()
|
||||
.getGenerateCodeForResources());
|
||||
if (worker.isCodeAutogenerated()) {
|
||||
worker.setCodeAutogenerated(configurationDAO.getConfiguration().getGenerateCodeForResources());
|
||||
if ( worker.isCodeAutogenerated() ) {
|
||||
setDefaultCode();
|
||||
}
|
||||
localizationsAssigner = new MultipleCriterionActiveAssigner(
|
||||
criterionDAO, worker, PredefinedCriterionTypes.LOCATION);
|
||||
localizationsAssigner =
|
||||
new MultipleCriterionActiveAssigner(criterionDAO, worker, PredefinedCriterionTypes.LOCATION);
|
||||
|
||||
boundUser = null;
|
||||
}
|
||||
|
||||
|
|
@ -250,9 +248,10 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
forceLoadCalendar(this.worker);
|
||||
forceLoadUser(this.worker);
|
||||
this.boundUser = this.worker.getUser();
|
||||
localizationsAssigner = new MultipleCriterionActiveAssigner(
|
||||
criterionDAO, this.worker,
|
||||
PredefinedCriterionTypes.LOCATION);
|
||||
|
||||
localizationsAssigner =
|
||||
new MultipleCriterionActiveAssigner(criterionDAO, this.worker, PredefinedCriterionTypes.LOCATION);
|
||||
|
||||
initOldCodes();
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -624,15 +623,14 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public void confirmRemove(Worker worker, boolean removeBoundUser)
|
||||
throws InstanceNotFoundException {
|
||||
public void confirmRemove(Worker worker, boolean removeBoundUser) throws InstanceNotFoundException {
|
||||
resourceDAO.remove(worker.getId());
|
||||
|
||||
User user = getBoundUserFromDB(worker);
|
||||
if (removeBoundUser) {
|
||||
if ( removeBoundUser ) {
|
||||
userDAO.remove(user);
|
||||
} else {
|
||||
if (user != null) {
|
||||
if ( user != null ) {
|
||||
user.removeRole(UserRole.ROLE_BOUND_USER);
|
||||
userDAO.save(user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,8 +88,7 @@ import org.zkoss.zul.impl.api.InputElement;
|
|||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*/
|
||||
public abstract class TreeController<T extends ITreeNode<T>> extends
|
||||
GenericForwardComposer {
|
||||
public abstract class TreeController<T extends ITreeNode<T>> extends GenericForwardComposer {
|
||||
|
||||
private static final ValidatorFactory validatorFactory = Validation
|
||||
.buildDefaultValidatorFactory();
|
||||
|
|
@ -238,11 +237,11 @@ public abstract class TreeController<T extends ITreeNode<T>> extends
|
|||
Textbox name = (Textbox) cmp.getFellow("newOrderElementName");
|
||||
Intbox hours = (Intbox) cmp.getFellow("newOrderElementHours");
|
||||
|
||||
if (StringUtils.isEmpty(name.getValue())) {
|
||||
if ( StringUtils.isEmpty(name.getValue()) ) {
|
||||
throw new WrongValueException(name, _("cannot be empty"));
|
||||
}
|
||||
|
||||
if (hours.getValue() == null) {
|
||||
if ( hours.getValue() == null ) {
|
||||
hours.setValue(0);
|
||||
}
|
||||
|
||||
|
|
@ -250,11 +249,10 @@ public abstract class TreeController<T extends ITreeNode<T>> extends
|
|||
|
||||
// Parse hours
|
||||
try {
|
||||
if (tree.getSelectedCount() == 1) {
|
||||
if ( tree.getSelectedCount() == 1 ) {
|
||||
T node = getSelectedNode();
|
||||
|
||||
T newNode = getModel().addElementAt(node, name.getValue(),
|
||||
hours.getValue());
|
||||
T newNode = getModel().addElementAt(node, name.getValue(), hours.getValue());
|
||||
getRenderer().refreshHoursValueForThisNodeAndParents(newNode);
|
||||
getRenderer().refreshBudgetValueForThisNodeAndParents(newNode);
|
||||
|
||||
|
|
@ -262,13 +260,12 @@ public abstract class TreeController<T extends ITreeNode<T>> extends
|
|||
// to select the proper element to focus
|
||||
reloadTreeUIAfterChanges();
|
||||
|
||||
if (node.isLeaf() && !node.isEmptyLeaf()) {
|
||||
if ( node.isLeaf() && !node.isEmptyLeaf() ) {
|
||||
// Then a new container will be created
|
||||
nameTextbox = getRenderer().getNameTextbox(node);
|
||||
} else {
|
||||
// select the parent row to add new children ASAP
|
||||
tree.setSelectedItem(getRenderer().getTreeitemForNode(
|
||||
newNode.getParent().getThis()));
|
||||
tree.setSelectedItem(getRenderer().getTreeitemForNode(newNode.getParent().getThis()));
|
||||
}
|
||||
} else {
|
||||
getModel().addElement(name.getValue(), hours.getValue());
|
||||
|
|
@ -285,7 +282,7 @@ public abstract class TreeController<T extends ITreeNode<T>> extends
|
|||
name.setValue("");
|
||||
hours.setValue(0);
|
||||
|
||||
if (nameTextbox != null) {
|
||||
if ( nameTextbox != null ) {
|
||||
nameTextbox.focus();
|
||||
} else {
|
||||
name.focus();
|
||||
|
|
|
|||
|
|
@ -75,8 +75,7 @@ public class ExportTimesheetsToTimTest {
|
|||
|
||||
@Before
|
||||
public void loadProperties() throws FileNotFoundException, IOException {
|
||||
String filename = System.getProperty("user.dir")
|
||||
+ "/../scripts/tim-connector/tim-conn.properties";
|
||||
String filename = System.getProperty("user.dir") + "/../scripts/tim-connector/tim-conn.properties";
|
||||
properties = new Properties();
|
||||
properties.load(new FileInputStream(filename));
|
||||
}
|
||||
|
|
@ -159,30 +158,24 @@ public class ExportTimesheetsToTimTest {
|
|||
@Test
|
||||
@Transactional
|
||||
@Ignore("Only working if you have a Tim server configured")
|
||||
public void testExportTimesheetsToTimWithValidCodeAndOrder()
|
||||
throws ConnectorException {
|
||||
public void testExportTimesheetsToTimWithValidCodeAndOrder() throws ConnectorException {
|
||||
Order order = givenOrder();
|
||||
exportTimesheetsToTim.exportTimesheets("5160", order);
|
||||
boolean result = exportTimesheetsToTim.getSynchronizationInfo()
|
||||
.isSuccessful();
|
||||
if (!result) {
|
||||
boolean result = exportTimesheetsToTim.getSynchronizationInfo().isSuccessful();
|
||||
if ( !result ) {
|
||||
fail("Export timesheets to tim failed");
|
||||
}
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test(expected = ConnectorException.class)
|
||||
@Transactional
|
||||
public void testExportTimesheetsToTimWithInvalidCode()
|
||||
throws ConnectorException {
|
||||
public void testExportTimesheetsToTimWithInvalidCode() throws ConnectorException {
|
||||
Order order = givenOrder();
|
||||
exportTimesheetsToTim.exportTimesheets("", order);
|
||||
}
|
||||
|
||||
@Test(expected = ConnectorException.class)
|
||||
@Transactional
|
||||
public void testExportTimesheetsToTimWithOrderNull()
|
||||
throws ConnectorException {
|
||||
public void testExportTimesheetsToTimWithOrderNull() throws ConnectorException {
|
||||
exportTimesheetsToTim.exportTimesheets("5160", null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -97,8 +97,7 @@ import org.zkoss.zk.ui.Desktop;
|
|||
WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE })
|
||||
public class OrderModelTest {
|
||||
|
||||
public static OrderVersion setupVersionUsing(
|
||||
IScenarioManager scenarioManager, Order order) {
|
||||
public static OrderVersion setupVersionUsing(IScenarioManager scenarioManager, Order order) {
|
||||
Scenario current = scenarioManager.getCurrent();
|
||||
OrderVersion result = OrderVersion.createInitialVersion(current);
|
||||
order.setVersionForScenario(current, result);
|
||||
|
|
@ -168,13 +167,11 @@ public class OrderModelTest {
|
|||
}
|
||||
|
||||
private PlanningState createPlanningStateFor(final Order newOrder) {
|
||||
return adHocTransaction
|
||||
.runOnAnotherReadOnlyTransaction(new IOnTransaction<PlanningState>() {
|
||||
return adHocTransaction.runOnAnotherReadOnlyTransaction(new IOnTransaction<PlanningState>() {
|
||||
|
||||
@Override
|
||||
public PlanningState execute() {
|
||||
return planningStateCreator.createOn(mockDesktop(),
|
||||
newOrder);
|
||||
return planningStateCreator.createOn(mockDesktop(), newOrder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -186,25 +183,29 @@ public class OrderModelTest {
|
|||
order.setName("name");
|
||||
order.setResponsible("responsible");
|
||||
order.setCode("code-" + UUID.randomUUID());
|
||||
BaseCalendar calendar = adHocTransaction
|
||||
.runOnReadOnlyTransaction(new IOnTransaction<BaseCalendar>() {
|
||||
|
||||
BaseCalendar calendar = adHocTransaction.runOnReadOnlyTransaction(new IOnTransaction<BaseCalendar>() {
|
||||
|
||||
@Override
|
||||
public BaseCalendar execute() {
|
||||
BaseCalendar result = configurationDAO
|
||||
.getConfigurationWithReadOnlyTransaction()
|
||||
.getDefaultCalendar();
|
||||
|
||||
BaseCalendar result =
|
||||
configurationDAO.getConfigurationWithReadOnlyTransaction().getDefaultCalendar();
|
||||
|
||||
BaseCalendarModel.forceLoadBaseCalendar(result);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
order.setCalendar(calendar);
|
||||
return order;
|
||||
}
|
||||
|
||||
private ExternalCompany createValidExternalCompany() {
|
||||
ExternalCompany externalCompany = ExternalCompany.create(UUID
|
||||
.randomUUID().toString(), UUID.randomUUID().toString());
|
||||
ExternalCompany externalCompany = ExternalCompany.create(
|
||||
UUID.randomUUID().toString(),
|
||||
UUID.randomUUID().toString());
|
||||
|
||||
externalCompanyDAO.save(externalCompany);
|
||||
return externalCompany;
|
||||
}
|
||||
|
|
@ -312,8 +313,7 @@ public class OrderModelTest {
|
|||
@Test(expected = ValidationException.class)
|
||||
@Transactional
|
||||
@Ignore("FIXME pending review after rename to libreplan")
|
||||
public void shouldSendValidationExceptionIfEndDateIsBeforeThanStartingDate()
|
||||
throws ValidationException {
|
||||
public void shouldSendValidationExceptionIfEndDateIsBeforeThanStartingDate() throws ValidationException {
|
||||
Order order = createValidOrder();
|
||||
order.setDeadline(year(0));
|
||||
orderModel.setPlanningState(createPlanningStateFor(order));
|
||||
|
|
@ -332,19 +332,17 @@ public class OrderModelTest {
|
|||
|
||||
@Test
|
||||
@Ignore("FIXME pending review after rename to libreplan")
|
||||
public void testOrderPreserved() throws ValidationException,
|
||||
InstanceNotFoundException {
|
||||
public void testOrderPreserved() throws ValidationException, InstanceNotFoundException {
|
||||
final Order order = createValidOrder();
|
||||
orderModel.setPlanningState(createPlanningStateFor(order));
|
||||
final OrderElement[] containers = new OrderLineGroup[10];
|
||||
for (int i = 0; i < containers.length; i++) {
|
||||
containers[i] = adHocTransaction
|
||||
.runOnTransaction(new IOnTransaction<OrderLineGroup>() {
|
||||
@Override
|
||||
public OrderLineGroup execute() {
|
||||
return OrderLineGroup.create();
|
||||
}
|
||||
});
|
||||
containers[i] = adHocTransaction.runOnTransaction(new IOnTransaction<OrderLineGroup>() {
|
||||
@Override
|
||||
public OrderLineGroup execute() {
|
||||
return OrderLineGroup.create();
|
||||
}
|
||||
});
|
||||
containers[i].setName("bla");
|
||||
containers[i].setCode("code-" + UUID.randomUUID());
|
||||
order.add(containers[i]);
|
||||
|
|
@ -372,26 +370,24 @@ public class OrderModelTest {
|
|||
try {
|
||||
Order reloaded = orderDAO.find(order.getId());
|
||||
List<OrderElement> elements = reloaded.getOrderElements();
|
||||
|
||||
for (OrderElement orderElement : elements) {
|
||||
assertThat(((OrderLineGroup) orderElement)
|
||||
.getIndirectAdvanceAssignments().size(),
|
||||
equalTo(2));
|
||||
assertThat(orderElement.getIndirectAdvanceAssignments().size(), equalTo(2));
|
||||
}
|
||||
|
||||
for (int i = 0; i < containers.length; i++) {
|
||||
assertThat(elements.get(i).getId(),
|
||||
equalTo(containers[i].getId()));
|
||||
assertThat(elements.get(i).getId(), equalTo(containers[i].getId()));
|
||||
}
|
||||
OrderLineGroup container = (OrderLineGroup) reloaded
|
||||
.getOrderElements().iterator().next();
|
||||
OrderLineGroup container = (OrderLineGroup) reloaded.getOrderElements().iterator().next();
|
||||
List<OrderElement> children = container.getChildren();
|
||||
|
||||
for (int i = 0; i < orderElements.length; i++) {
|
||||
assertThat(children.get(i).getId(),
|
||||
equalTo(orderElements[i].getId()));
|
||||
assertThat(children.get(i).getId(), equalTo(orderElements[i].getId()));
|
||||
}
|
||||
|
||||
for (int i = 1; i < containers.length; i++) {
|
||||
OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
|
||||
assertThat(orderLineGroup.getChildren().size(),
|
||||
equalTo(1));
|
||||
assertThat(orderLineGroup.getChildren().size(), equalTo(1));
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -22,22 +22,77 @@
|
|||
package org.libreplan.web.planner.chart;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.libreplan.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_CONFIG_FILE;
|
||||
import static org.libreplan.web.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_FILE;
|
||||
import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_CONFIG_TEST_FILE;
|
||||
import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.libreplan.business.IDataBootstrap;
|
||||
import org.libreplan.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||
import org.libreplan.business.common.IAdHocTransactionService;
|
||||
import org.libreplan.business.common.IOnTransaction;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.orders.entities.HoursGroup;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderElement;
|
||||
import org.libreplan.business.orders.entities.OrderLine;
|
||||
|
||||
import org.libreplan.business.planner.entities.IOrderEarnedValueCalculator;
|
||||
import org.libreplan.business.planner.entities.SpecificDayAssignmentsContainer;
|
||||
import org.libreplan.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.scenarios.entities.Scenario;
|
||||
import org.libreplan.business.workingday.ResourcesPerDay;
|
||||
import org.libreplan.web.calendars.BaseCalendarModel;
|
||||
import org.libreplan.web.calendars.IBaseCalendarModel;
|
||||
import org.libreplan.web.common.IConfigurationModel;
|
||||
import org.libreplan.web.orders.IOrderModel;
|
||||
import org.libreplan.web.planner.order.PlanningStateCreator;
|
||||
import org.libreplan.web.planner.order.PlanningStateCreator.PlanningState;
|
||||
import org.libreplan.web.resources.worker.IAssignedCriterionsModel;
|
||||
import org.libreplan.web.resources.worker.IWorkerModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.zkforge.timeplot.Timeplot;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
import org.zkoss.zk.ui.Desktop;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Tests for {@link ChartFiller}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {
|
||||
BUSINESS_SPRING_CONFIG_FILE,
|
||||
|
||||
WEBAPP_SPRING_CONFIG_FILE,
|
||||
WEBAPP_SPRING_CONFIG_TEST_FILE,
|
||||
|
||||
WEBAPP_SPRING_SECURITY_CONFIG_FILE,
|
||||
WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE
|
||||
})
|
||||
@Transactional
|
||||
public class ChartFillerTest {
|
||||
|
||||
private ChartFiller chartFiller = new ChartFiller() {
|
||||
|
|
@ -64,26 +119,207 @@ public class ChartFillerTest {
|
|||
|
||||
@Test
|
||||
public void testCalculatedValueForEveryDay() {
|
||||
SortedMap<LocalDate, BigDecimal> result = chartFiller
|
||||
.calculatedValueForEveryDay(givenExampleMap(), START_DAY,
|
||||
FINISH_DAY);
|
||||
SortedMap<LocalDate, BigDecimal> result =
|
||||
chartFiller.calculatedValueForEveryDay(givenExampleMap(), START_DAY, FINISH_DAY);
|
||||
|
||||
assertThat(result.get(START_DAY), equalTo(BigDecimal.ZERO.setScale(2)));
|
||||
assertThat(result.get(START_DAY.plusDays(1)),
|
||||
equalTo(new BigDecimal(25).setScale(2)));
|
||||
assertThat(result.get(START_DAY.plusDays(1)), equalTo(new BigDecimal(25).setScale(2)));
|
||||
|
||||
assertThat(result.get(FIRST_DAY), equalTo(new BigDecimal(100)
|
||||
.setScale(2)));
|
||||
assertThat(result.get(FIRST_DAY.plusDays(1)), equalTo(new BigDecimal(
|
||||
105).setScale(2)));
|
||||
assertThat(result.get(FIRST_DAY), equalTo(new BigDecimal(100).setScale(2)));
|
||||
assertThat(result.get(FIRST_DAY.plusDays(1)), equalTo(new BigDecimal(105).setScale(2)));
|
||||
|
||||
assertThat(result.get(LAST_DAY), equalTo(new BigDecimal(150)
|
||||
.setScale(2)));
|
||||
assertThat(result.get(LAST_DAY.plusDays(1)),
|
||||
equalTo(new BigDecimal(150).setScale(2)));
|
||||
assertThat(result.get(LAST_DAY), equalTo(new BigDecimal(150).setScale(2)));
|
||||
assertThat(result.get(LAST_DAY.plusDays(1)), equalTo(new BigDecimal(150).setScale(2)));
|
||||
|
||||
assertThat(result.get(FINISH_DAY), equalTo(new BigDecimal(150)
|
||||
.setScale(2)));
|
||||
assertThat(result.get(FINISH_DAY), equalTo(new BigDecimal(150).setScale(2)));
|
||||
}
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap defaultAdvanceTypesBootstrapListener;
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap scenariosBootstrap;
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap configurationBootstrap;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService transactionService;
|
||||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
|
||||
IOnTransaction<Void> load = new IOnTransaction<Void>() {
|
||||
|
||||
@Override
|
||||
public Void execute() {
|
||||
defaultAdvanceTypesBootstrapListener.loadRequiredData();
|
||||
configurationBootstrap.loadRequiredData();
|
||||
scenariosBootstrap.loadRequiredData();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
transactionService.runOnAnotherTransaction(load);
|
||||
}
|
||||
|
||||
// Testing BAC values
|
||||
// 1. Create Worker
|
||||
// 2. Create Project
|
||||
// 3. Create 2 Tasks
|
||||
// 4. Assign Resources to Tasks
|
||||
// 5. Check BAC values
|
||||
|
||||
@Resource
|
||||
IBaseCalendarModel baseCalendarModel;
|
||||
|
||||
@Autowired
|
||||
IBaseCalendarDAO baseCalendarDAO;
|
||||
|
||||
@Autowired
|
||||
IConfigurationModel configurationModel;
|
||||
|
||||
@Test
|
||||
public void testBAC(){
|
||||
createAndSaveWorker();
|
||||
createAndSaveProject();
|
||||
createAndSaveTwoTasksForProject();
|
||||
assignAndSaveResourcesForTasks();
|
||||
|
||||
BigDecimal BAC = earnedValueCalculator.getBudgetAtCompletion(orderModel.getOrder());
|
||||
assertEquals(BAC, new BigDecimal(50));
|
||||
}
|
||||
|
||||
// For creating worker
|
||||
@Autowired
|
||||
IWorkerModel workerModel;
|
||||
|
||||
@Autowired
|
||||
IAssignedCriterionsModel assignedCriterionsModel;
|
||||
|
||||
private void createAndSaveWorker() {
|
||||
workerModel.prepareForCreate();
|
||||
workerModel.getWorker().setFirstName("Neil");
|
||||
workerModel.getWorker().setSurname("Armstrong");
|
||||
workerModel.getWorker().setNif("666");
|
||||
workerModel.getAssignedCriterionsModel().prepareForCreate(workerModel.getWorker());
|
||||
workerModel.save();
|
||||
}
|
||||
|
||||
// For creating project
|
||||
@Autowired
|
||||
IOrderModel orderModel;
|
||||
|
||||
@Autowired
|
||||
private PlanningStateCreator planningStateCreator;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService adHocTransaction;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
private void createAndSaveProject(){
|
||||
final Order project = Order.create();
|
||||
project.setDescription("Goal of project: do not be thirsty");
|
||||
|
||||
// Create initDate
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.clear();
|
||||
calendar.set(Calendar.YEAR, 2016);
|
||||
|
||||
project.setInitDate(calendar.getTime());
|
||||
project.setName("To be not thirsty");
|
||||
project.setResponsible("human");
|
||||
project.setCode("code-" + UUID.randomUUID());
|
||||
|
||||
BaseCalendar baseCalendar = adHocTransaction.runOnReadOnlyTransaction(new IOnTransaction<BaseCalendar>() {
|
||||
@Override
|
||||
public BaseCalendar execute() {
|
||||
BaseCalendar result =
|
||||
configurationDAO.getConfigurationWithReadOnlyTransaction().getDefaultCalendar();
|
||||
|
||||
BaseCalendarModel.forceLoadBaseCalendar(result);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
project.setCalendar(baseCalendar);
|
||||
|
||||
// Create planningState
|
||||
PlanningState planningState =
|
||||
adHocTransaction.runOnAnotherReadOnlyTransaction(new IOnTransaction<PlanningState>() {
|
||||
|
||||
@Override
|
||||
public PlanningStateCreator.PlanningState execute() {
|
||||
return planningStateCreator.createOn(EasyMock.createNiceMock(Desktop.class), project);
|
||||
}
|
||||
});
|
||||
|
||||
orderModel.setPlanningState(planningState);
|
||||
orderModel.save();
|
||||
}
|
||||
|
||||
private void createAndSaveTwoTasksForProject(){
|
||||
OrderElement task1 = OrderLine.createOrderLineWithUnfixedPercentage(10);
|
||||
task1.setName("Take bottle");
|
||||
task1.setCode(UUID.randomUUID().toString());
|
||||
for (HoursGroup current : task1.getHoursGroups()) current.setCode(UUID.randomUUID().toString());
|
||||
|
||||
OrderElement task2 = OrderLine.createOrderLineWithUnfixedPercentage(40);
|
||||
task2.setName("Drink water");
|
||||
task2.setCode(UUID.randomUUID().toString());
|
||||
for (HoursGroup current : task2.getHoursGroups()) current.setCode(UUID.randomUUID().toString());
|
||||
|
||||
orderModel.getOrder().add(task1);
|
||||
orderModel.getOrder().add(task2);
|
||||
|
||||
orderModel.save();
|
||||
}
|
||||
|
||||
// For assigning resources to tasks
|
||||
@Autowired
|
||||
private IOrderEarnedValueCalculator earnedValueCalculator;
|
||||
|
||||
private void assignAndSaveResourcesForTasks(){
|
||||
// Task 1
|
||||
Task task1 = (Task) orderModel.getOrder().getAllChildrenAssociatedTaskElements().get(0);
|
||||
SpecificResourceAllocation specificResourceAllocation1 = SpecificResourceAllocation.create(task1);
|
||||
specificResourceAllocation1.setResource(workerModel.getWorker());
|
||||
|
||||
Scenario orderScenario1 = null;
|
||||
for (Scenario scenario : orderModel.getOrder().getScenarios().keySet()) {
|
||||
orderScenario1 = scenario;
|
||||
}
|
||||
specificResourceAllocation1.copyAssignments(orderScenario1, orderScenario1);
|
||||
|
||||
specificResourceAllocation1.allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
for (SpecificDayAssignmentsContainer item : specificResourceAllocation1.getSpecificDayAssignmentsContainers()) {
|
||||
item.addAll(specificResourceAllocation1.getAssignments());
|
||||
}
|
||||
|
||||
task1.addResourceAllocation(specificResourceAllocation1);
|
||||
|
||||
|
||||
// Task 2
|
||||
Task task2 = (Task) orderModel.getOrder().getAllChildrenAssociatedTaskElements().get(1);
|
||||
SpecificResourceAllocation specificResourceAllocation2 = SpecificResourceAllocation.create(task2);
|
||||
specificResourceAllocation2.setResource(workerModel.getWorker());
|
||||
|
||||
Scenario orderScenario2 = null;
|
||||
for (Scenario scenario : orderModel.getOrder().getScenarios().keySet()) {
|
||||
orderScenario2 = scenario;
|
||||
}
|
||||
specificResourceAllocation2.copyAssignments(orderScenario2, orderScenario2);
|
||||
|
||||
specificResourceAllocation2.allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
for (SpecificDayAssignmentsContainer item : specificResourceAllocation2.getSpecificDayAssignmentsContainers()) {
|
||||
item.addAll(specificResourceAllocation2.getAssignments());
|
||||
}
|
||||
|
||||
task2.addResourceAllocation(specificResourceAllocation2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,9 +68,7 @@ public class WorkerModelTest {
|
|||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testWorkerValid() throws ValidationException,
|
||||
InstanceNotFoundException {
|
||||
public void testWorkerValid() throws ValidationException, InstanceNotFoundException {
|
||||
|
||||
IResourceDAO resourceDAOMock = createMock(IResourceDAO.class);
|
||||
ICriterionDAO criterionServiceMock = createMock(ICriterionDAO.class);
|
||||
|
|
@ -78,20 +76,17 @@ public class WorkerModelTest {
|
|||
workerToReturn.setFirstName("firstName");
|
||||
workerToReturn.setSurname("surname");
|
||||
workerToReturn.setNif("232344243");
|
||||
|
||||
// expectations
|
||||
List<Criterion> criterions = new ArrayList<Criterion>();
|
||||
expect(
|
||||
criterionServiceMock
|
||||
.findByType(PredefinedCriterionTypes.LOCATION))
|
||||
.andReturn(criterions).anyTimes();
|
||||
expect(resourceDAOMock.find(workerToReturn.getId()))
|
||||
.andReturn(workerToReturn);
|
||||
expect(criterionServiceMock.findByType(PredefinedCriterionTypes.LOCATION)).andReturn(criterions).anyTimes();
|
||||
expect(resourceDAOMock.find(workerToReturn.getId())).andReturn(workerToReturn);
|
||||
resourceDAOMock.save(workerToReturn);
|
||||
workerToReturn.checkNotOverlaps();
|
||||
replay(resourceDAOMock, criterionServiceMock);
|
||||
|
||||
// perform actions
|
||||
WorkerModel workerModel = new WorkerModel(resourceDAOMock,
|
||||
criterionServiceMock);
|
||||
WorkerModel workerModel = new WorkerModel(resourceDAOMock, criterionServiceMock);
|
||||
|
||||
workerModel.prepareEditFor(workerToReturn);
|
||||
workerModel.save();
|
||||
|
|
@ -100,20 +95,16 @@ public class WorkerModelTest {
|
|||
@Ignore
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Transactional
|
||||
public void testWorkerInvalid() throws ValidationException,
|
||||
InstanceNotFoundException, IllegalStateException {
|
||||
public void testWorkerInvalid() throws ValidationException, InstanceNotFoundException, IllegalStateException {
|
||||
|
||||
IResourceDAO resourceDAOMock = createMock(IResourceDAO.class);
|
||||
ICriterionDAO criterionServiceMock = createMock(ICriterionDAO.class);
|
||||
final Worker workerToReturn = Worker.create();
|
||||
|
||||
// expectations
|
||||
List<Criterion> criterions = new ArrayList<Criterion>();
|
||||
expect(
|
||||
criterionServiceMock
|
||||
.findByType(PredefinedCriterionTypes.LOCATION))
|
||||
.andReturn(criterions).anyTimes();
|
||||
expect(resourceDAOMock.find(workerToReturn.getId())).andReturn(
|
||||
workerToReturn);
|
||||
expect(criterionServiceMock.findByType(PredefinedCriterionTypes.LOCATION)).andReturn(criterions).anyTimes();
|
||||
expect(resourceDAOMock.find(workerToReturn.getId())).andReturn(workerToReturn);
|
||||
resourceDAOMock.save(workerToReturn);
|
||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
||||
@Override
|
||||
|
|
@ -124,9 +115,9 @@ public class WorkerModelTest {
|
|||
}
|
||||
});
|
||||
replay(resourceDAOMock, criterionServiceMock);
|
||||
|
||||
// perform actions
|
||||
WorkerModel workerModel = new WorkerModel(resourceDAOMock,
|
||||
criterionServiceMock);
|
||||
WorkerModel workerModel = new WorkerModel(resourceDAOMock, criterionServiceMock);
|
||||
workerModel.prepareEditFor(workerToReturn);
|
||||
workerModel.save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,10 +29,9 @@ package org.libreplan.web.test;
|
|||
*/
|
||||
public class WebappGlobalNames {
|
||||
|
||||
public final static String WEBAPP_SPRING_CONFIG_TEST_FILE =
|
||||
"classpath:/libreplan-webapp-spring-config-test.xml";
|
||||
public final static String WEBAPP_SPRING_CONFIG_TEST_FILE = "classpath:/libreplan-webapp-spring-config-test.xml";
|
||||
|
||||
public final static String WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE =
|
||||
"classpath:/libreplan-webapp-spring-security-config-test.xml";
|
||||
"classpath:/libreplan-webapp-spring-security-config-test.xml";
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue