ItEr21S04ArquitecturaServidorItEr20S04: Removed use of ICriterionTypeService.
Signed-off-by: Óscar González Fernández <ogonzalez@igalia.com> Refactored some code in CriterionsBootstrap. Some catchs that did nothing now throw an exception.
This commit is contained in:
parent
50e1d83bc6
commit
13f19fa1a5
13 changed files with 73 additions and 57 deletions
|
|
@ -6,13 +6,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.services.ICriterionService;
|
||||
import org.navalplanner.business.resources.services.ICriterionTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -34,7 +37,7 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
|
|||
private ICriterionService criterionService;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeService criterionTypeService;
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
@Autowired
|
||||
private List<ICriterionTypeProvider> providers;
|
||||
|
|
@ -45,40 +48,44 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
|
|||
@Override
|
||||
@Transactional
|
||||
public void loadRequiredData() {
|
||||
LOG.debug("### loadRequiredData()");
|
||||
|
||||
Map<CriterionType, List<String>> typesWithCriterions = getTypesWithCriterions();
|
||||
|
||||
// Insert predefined criterions
|
||||
for (Entry<CriterionType, List<String>> entry :
|
||||
typesWithCriterions.entrySet()) {
|
||||
// Create PredefinedCriterionType
|
||||
CriterionType criterionType = entry.getKey();
|
||||
try {
|
||||
criterionTypeService.createIfNotExists(criterionType);
|
||||
} catch (ValidationException e) {
|
||||
|
||||
}
|
||||
// Retrieve existing criterionType if not exists
|
||||
if (criterionType.getId() == null) {
|
||||
criterionType = criterionTypeService.findUniqueByName(criterionType.getName());
|
||||
}
|
||||
|
||||
CriterionType criterionType = retrieveOrCreate(entry.getKey());
|
||||
// Create predefined criterions for criterionType
|
||||
for (String criterionName : entry.getValue()) {
|
||||
try {
|
||||
Criterion criterion = new Criterion(criterionName, criterionType);
|
||||
criterionService.createIfNotExists(criterion);
|
||||
|
||||
LOG.debug("### Create criterion: (" + criterionName +
|
||||
"; " + criterionType.getName());
|
||||
} catch (ValidationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ensureCriterionExists(criterionName, criterionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureCriterionExists(String criterionName,
|
||||
CriterionType criterionType) {
|
||||
try {
|
||||
Criterion criterion = new Criterion(criterionName, criterionType);
|
||||
criterionService.createIfNotExists(criterion);
|
||||
} catch (ValidationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private CriterionType retrieveOrCreate(CriterionType criterionType) {
|
||||
if (!criterionTypeDAO.exists(criterionType.getId())
|
||||
&& !criterionTypeDAO.existsByName(criterionType)) {
|
||||
criterionTypeDAO.save(criterionType);
|
||||
}else{
|
||||
try {
|
||||
criterionType = criterionTypeDAO
|
||||
.findUniqueByName(criterionType.getName());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return criterionType;
|
||||
}
|
||||
|
||||
private Map<CriterionType, List<String>> getTypesWithCriterions() {
|
||||
HashMap<CriterionType, List<String>> result = new HashMap<CriterionType, List<String>>();
|
||||
for (ICriterionTypeProvider provider : providers) {
|
||||
|
|
|
|||
|
|
@ -64,4 +64,10 @@ public class CriterionTypeDAO extends GenericDAOHibernate<CriterionType, Long>
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CriterionType> getCriterionTypes() {
|
||||
return list(CriterionType.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,6 @@ public interface ICriterionTypeDAO extends IGenericDAO<CriterionType, Long> {
|
|||
public boolean existsByName(CriterionType criterionType);
|
||||
|
||||
public void removeByName(CriterionType criterionType);
|
||||
|
||||
List<CriterionType> getCriterionTypes();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import java.util.Set;
|
|||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.resources.services.ICriterionTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
|
@ -18,9 +16,6 @@ import org.springframework.stereotype.Component;
|
|||
public class CriterionType extends BaseEntity implements
|
||||
ICriterionType<Criterion> {
|
||||
|
||||
@Autowired
|
||||
ICriterionTypeService criterionTypeService;
|
||||
|
||||
@NotEmpty
|
||||
private String name;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
|||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.daos.CriterionDAO;
|
||||
import org.navalplanner.business.resources.daos.ICriterionDAO;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
|
|
@ -44,7 +45,7 @@ public class CriterionServiceImpl implements ICriterionService {
|
|||
private IResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeService criterionTypeService;
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
public boolean exists(Criterion criterion) {
|
||||
return criterionDAO.exists(criterion.getId())
|
||||
|
|
@ -91,10 +92,16 @@ public class CriterionServiceImpl implements ICriterionService {
|
|||
}
|
||||
|
||||
private CriterionType saveCriterionType(CriterionType criterionType) throws ValidationException {
|
||||
if (criterionTypeService.exists(criterionType)) {
|
||||
criterionType = criterionTypeService.findUniqueByName(criterionType.getName());
|
||||
if (criterionTypeDAO.exists(criterionType.getId())
|
||||
|| criterionTypeDAO.existsByName(criterionType)) {
|
||||
try {
|
||||
criterionType = criterionTypeDAO
|
||||
.findUniqueByName(criterionType.getName());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
criterionTypeService.save(criterionType);
|
||||
criterionTypeDAO.save(criterionType);
|
||||
}
|
||||
|
||||
return criterionType;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ public class CriterionTypeServiceImpl implements ICriterionTypeService {
|
|||
return criterionTypeDAO.list(CriterionType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(CriterionType criterionType) throws InstanceNotFoundException {
|
||||
if (criterionType.getId() != null ) {
|
||||
criterionTypeDAO.remove(criterionType.getId());
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package org.navalplanner.business.resources.services;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
|
||||
/**
|
||||
|
|
@ -22,8 +21,6 @@ public interface ICriterionTypeService {
|
|||
|
||||
List<CriterionType> getAll();
|
||||
|
||||
void remove(CriterionType criterionType) throws InstanceNotFoundException;
|
||||
|
||||
void save(CriterionType entity);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.resources.bootstrap.ICriterionsBootstrap;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.ICriterion;
|
||||
|
|
@ -31,7 +31,7 @@ public class ResourceServiceImpl implements IResourceService {
|
|||
private IResourceDAO resourceDao;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeService criterionTypeService;
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
|
||||
@Transactional
|
||||
|
|
@ -46,7 +46,7 @@ public class ResourceServiceImpl implements IResourceService {
|
|||
}
|
||||
|
||||
private void checkResourceIsOk(Resource resource) {
|
||||
List<CriterionType> types = criterionTypeService.getAll();
|
||||
List<CriterionType> types = criterionTypeDAO.getCriterionTypes();
|
||||
resource.checkNotOverlaps(types);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class WorkReportType extends BaseEntity {
|
|||
|
||||
private String name;
|
||||
|
||||
private Set<CriterionType> criterionTypes;
|
||||
private Set<CriterionType> criterionTypes = new HashSet<CriterionType>();
|
||||
|
||||
public WorkReportType() {
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,9 @@ import java.util.Set;
|
|||
import org.navalplanner.business.orders.daos.IOrderElementDAO;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.resources.bootstrap.ICriterionsBootstrap;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.services.ICriterionService;
|
||||
import org.navalplanner.business.resources.services.ICriterionTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -36,7 +33,7 @@ public class OrderElementModel implements IOrderElementModel {
|
|||
private ICriterionTypeDAO criterionTypeDao;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeService criterionTypeService;
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
private Map<String, CriterionType> mapCriterionTypes = new HashMap<String, CriterionType>();
|
||||
|
||||
|
|
@ -59,6 +56,7 @@ public class OrderElementModel implements IOrderElementModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CriterionType> getCriterionTypes() {
|
||||
List<CriterionType> result = new ArrayList<CriterionType>();
|
||||
|
||||
|
|
@ -70,6 +68,7 @@ public class OrderElementModel implements IOrderElementModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public CriterionType getCriterionTypeByName(String name) {
|
||||
if (mapCriterionTypes.isEmpty())
|
||||
loadCriterionTypes();
|
||||
|
|
@ -78,7 +77,7 @@ public class OrderElementModel implements IOrderElementModel {
|
|||
}
|
||||
|
||||
private void loadCriterionTypes() {
|
||||
for (CriterionType criterionType : criterionTypeService.getAll()) {
|
||||
for (CriterionType criterionType : criterionTypeDAO.getCriterionTypes()) {
|
||||
mapCriterionTypes.put(criterionType.getName(), criterionType);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ import org.navalplanner.business.orders.entities.Order;
|
|||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.planner.services.ITaskElementService;
|
||||
import org.navalplanner.business.resources.daos.ICriterionDAO;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.services.ICriterionService;
|
||||
import org.navalplanner.business.resources.services.ICriterionTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -41,7 +41,7 @@ public class OrderModel implements IOrderModel {
|
|||
ICriterionService criterionService;
|
||||
|
||||
@Autowired
|
||||
ICriterionTypeService criterionTypeService;
|
||||
ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
private static final Map<CriterionType, List<Criterion>> mapCriterions = new HashMap<CriterionType, List<Criterion>>();
|
||||
|
||||
|
|
@ -78,7 +78,8 @@ public class OrderModel implements IOrderModel {
|
|||
|
||||
private void loadCriterions() {
|
||||
mapCriterions.clear();
|
||||
List<CriterionType> criterionTypes = criterionTypeService.getAll();
|
||||
List<CriterionType> criterionTypes = criterionTypeDAO
|
||||
.getCriterionTypes();
|
||||
for (CriterionType criterionType : criterionTypes) {
|
||||
List<Criterion> criterions = new ArrayList<Criterion>(
|
||||
criterionService.getCriterionsFor(criterionType));
|
||||
|
|
@ -105,6 +106,7 @@ public class OrderModel implements IOrderModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void prepareForCreate() {
|
||||
loadCriterions();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.hibernate.validator.ClassValidator;
|
|||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.bootstrap.ICriterionsBootstrap;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||
|
|
@ -19,7 +19,6 @@ import org.navalplanner.business.resources.entities.ICriterionType;
|
|||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.business.resources.services.ICriterionService;
|
||||
import org.navalplanner.business.resources.services.ICriterionTypeService;
|
||||
import org.navalplanner.business.resources.services.IResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -44,7 +43,7 @@ public class CriterionsModel implements ICriterionsModel {
|
|||
private ICriterionService criterionService;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeService criterionTypeService;
|
||||
private ICriterionTypeDAO criterionDAO;
|
||||
|
||||
@Autowired
|
||||
private IResourceService resourceService;
|
||||
|
|
@ -56,7 +55,7 @@ public class CriterionsModel implements ICriterionsModel {
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CriterionType> getTypes() {
|
||||
return criterionTypeService.getAll();
|
||||
return criterionDAO.getCriterionTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -85,6 +84,7 @@ public class CriterionsModel implements ICriterionsModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ICriterionType<?> getTypeFor(Criterion criterion) {
|
||||
for (ICriterionType<?> criterionType : getTypes()) {
|
||||
if (criterionType.contains(criterion))
|
||||
|
|
@ -116,6 +116,7 @@ public class CriterionsModel implements ICriterionsModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public boolean isApplyableToWorkers(Criterion criterion) {
|
||||
ICriterionType<?> type = getTypeFor(criterion);
|
||||
return type != null && type.criterionCanBeRelatedTo(Worker.class);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import org.hibernate.validator.ClassValidator;
|
|||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.services.ICriterionTypeService;
|
||||
import org.navalplanner.business.workreports.daos.IWorkReportTypeDAO;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -30,7 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
public class WorkReportTypeModel implements IWorkReportTypeModel {
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeService criterionTypeService;
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
@Autowired
|
||||
private IWorkReportTypeDAO workReportTypeDAO;
|
||||
|
|
@ -117,8 +117,9 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Set<CriterionType> getCriterionTypes() {
|
||||
return new HashSet<CriterionType>(criterionTypeService.getAll());
|
||||
return new HashSet<CriterionType>(criterionTypeDAO.getCriterionTypes());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue