Forced deletion of Label and Criterion parameters and session bandboxes after entities deletion
FEA: ItEr77S15FilteringEnhancements
This commit is contained in:
parent
d3e43e0592
commit
880f51704a
6 changed files with 77 additions and 4 deletions
|
|
@ -25,6 +25,8 @@ import java.util.List;
|
|||
|
||||
import org.libreplan.business.common.daos.IGenericDAO;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.labels.entities.Label;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.Worker;
|
||||
import org.libreplan.business.scenarios.entities.Scenario;
|
||||
import org.libreplan.business.users.entities.OrderAuthorization;
|
||||
|
|
@ -102,4 +104,8 @@ public interface IUserDAO extends IGenericDAO<User, Long>{
|
|||
|
||||
List<User> findAll();
|
||||
|
||||
public List<User> findByLabelFilterSetting(List<Label> removedLabels);
|
||||
|
||||
public List<User> findByCriterionFilterSetting(List<Criterion> criteria);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import org.hibernate.Criteria;
|
|||
import org.hibernate.criterion.Restrictions;
|
||||
import org.libreplan.business.common.daos.GenericDAOHibernate;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.labels.entities.Label;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.Worker;
|
||||
import org.libreplan.business.scenarios.entities.Scenario;
|
||||
import org.libreplan.business.users.entities.OrderAuthorization;
|
||||
|
|
@ -178,4 +180,18 @@ public class UserDAO extends GenericDAOHibernate<User, Long>
|
|||
return list(User.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findByLabelFilterSetting(List<Label> labels) {
|
||||
Criteria c = getSession().createCriteria(User.class);
|
||||
c.add(Restrictions.in("projectsFilterLabel", labels));
|
||||
return c.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findByCriterionFilterSetting(List<Criterion> criteria) {
|
||||
Criteria c = getSession().createCriteria(User.class);
|
||||
c.add(Restrictions.in("resourcesLoadFilterCriterion", criteria));
|
||||
return c.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreplan.web.common;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.web.common.components.finders.FilterPair;
|
||||
|
|
@ -59,7 +60,7 @@ public class FilterUtils {
|
|||
}
|
||||
|
||||
public static void writeProjectsParameters(List<Object> parameters) {
|
||||
Sessions.getCurrent().getAttribute("companyFilterLabel");
|
||||
Sessions.getCurrent().setAttribute("companyFilterLabel", parameters);
|
||||
}
|
||||
|
||||
public static void writeProjectsFilter(Date startDate, Date endDate,
|
||||
|
|
@ -95,8 +96,8 @@ public class FilterUtils {
|
|||
}
|
||||
|
||||
public static void writeResourceLoadsParameters(List<Object> parameters) {
|
||||
Sessions.getCurrent().getAttribute(
|
||||
"resourceLoadFilterWorkerOrCriterion");
|
||||
Sessions.getCurrent().setAttribute(
|
||||
"resourceLoadFilterWorkerOrCriterion", parameters);
|
||||
}
|
||||
|
||||
// Project gantt and WBS filter parameters
|
||||
|
|
@ -137,4 +138,15 @@ public class FilterUtils {
|
|||
Sessions.getCurrent().setAttribute(orderCode + "-tasknameFilter", name);
|
||||
}
|
||||
|
||||
public static void clearBandboxes() {
|
||||
writeProjectsParameters(null);
|
||||
writeResourceLoadsParameters(null);
|
||||
// Locate all order-specific bandboxes
|
||||
for (String key : (Set <String>) Sessions.getCurrent().getAttributes().keySet() ) {
|
||||
if (key.contains("-tasknameFilter")) {
|
||||
Sessions.getCurrent().setAttribute(key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ import org.libreplan.business.labels.daos.ILabelDAO;
|
|||
import org.libreplan.business.labels.daos.ILabelTypeDAO;
|
||||
import org.libreplan.business.labels.entities.Label;
|
||||
import org.libreplan.business.labels.entities.LabelType;
|
||||
import org.libreplan.business.users.daos.IUserDAO;
|
||||
import org.libreplan.business.users.entities.User;
|
||||
import org.libreplan.web.common.FilterUtils;
|
||||
import org.libreplan.web.common.IntegrationEntityModel;
|
||||
import org.libreplan.web.common.concurrentdetection.OnConcurrentModification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -65,8 +68,13 @@ public class LabelTypeModel extends IntegrationEntityModel implements
|
|||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Autowired
|
||||
private IUserDAO userDAO;
|
||||
|
||||
private LabelType labelType;
|
||||
|
||||
private List<Label> removedLabels = new ArrayList<Label>();
|
||||
|
||||
public LabelTypeModel() {
|
||||
|
||||
}
|
||||
|
|
@ -129,6 +137,15 @@ public class LabelTypeModel extends IntegrationEntityModel implements
|
|||
|
||||
generateCodes();
|
||||
labelTypeDAO.save(labelType);
|
||||
|
||||
if (!removedLabels.isEmpty()) {
|
||||
List<User> users = userDAO.findByLabelFilterSetting(removedLabels);
|
||||
for (User user : users) {
|
||||
user.setProjectsFilterLabel(null);
|
||||
userDAO.save(user);
|
||||
}
|
||||
FilterUtils.clearBandboxes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -233,6 +250,7 @@ public class LabelTypeModel extends IntegrationEntityModel implements
|
|||
@Override
|
||||
public void confirmDeleteLabel(Label label) {
|
||||
labelType.removeLabel(label);
|
||||
removedLabels.add(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -301,7 +301,8 @@ public class ResourceLoadController implements Composer {
|
|||
|
||||
List<FilterPair> filterPairs = (List<FilterPair>) FilterUtils
|
||||
.readResourceLoadsBandbox();
|
||||
if (filterPairs == null || filterPairs.isEmpty()) {
|
||||
if ((filterPairs == null || filterPairs.isEmpty())
|
||||
&& user.getResourcesLoadFilterCriterion() != null) {
|
||||
filterPairs = new ArrayList<FilterPair>();
|
||||
filterPairs.add(new FilterPair(
|
||||
ResourceAllocationFilterEnum.Criterion, user
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.Set;
|
|||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.annotations.Filters;
|
||||
import org.libreplan.business.common.IntegrationEntity;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
|
|
@ -44,6 +45,9 @@ import org.libreplan.business.resources.entities.CriterionType;
|
|||
import org.libreplan.business.resources.entities.ICriterionType;
|
||||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.resources.entities.Worker;
|
||||
import org.libreplan.business.users.daos.IUserDAO;
|
||||
import org.libreplan.business.users.entities.User;
|
||||
import org.libreplan.web.common.FilterUtils;
|
||||
import org.libreplan.web.common.IntegrationEntityModel;
|
||||
import org.libreplan.web.common.concurrentdetection.OnConcurrentModification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -78,12 +82,17 @@ public class CriterionsModel extends IntegrationEntityModel implements ICriterio
|
|||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Autowired
|
||||
private IUserDAO userDAO;
|
||||
|
||||
private CriterionType criterionType;
|
||||
|
||||
private Criterion criterion;
|
||||
|
||||
private ICriterionTreeModel criterionTreeModel;
|
||||
|
||||
private List<Criterion> removedCriterion = new ArrayList<Criterion>();
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CriterionType> getTypes() {
|
||||
|
|
@ -187,6 +196,16 @@ public class CriterionsModel extends IntegrationEntityModel implements ICriterio
|
|||
}
|
||||
criterionTreeModel.saveCriterions(criterionType);
|
||||
criterionTypeDAO.save(criterionType);
|
||||
|
||||
if (!removedCriterion.isEmpty()) {
|
||||
List<User> users = userDAO
|
||||
.findByCriterionFilterSetting(removedCriterion);
|
||||
for (User user : users) {
|
||||
user.setResourcesLoadFilterCriterion(null);
|
||||
userDAO.save(user);
|
||||
}
|
||||
FilterUtils.clearBandboxes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -263,6 +282,7 @@ public class CriterionsModel extends IntegrationEntityModel implements ICriterio
|
|||
@Override
|
||||
public void addForRemoval(Criterion criterion) {
|
||||
criterionType.getCriterions().remove(criterion);
|
||||
removedCriterion.add(criterion);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue