ItEr60S04ValidacionEProbasFuncionaisItEr59S04 : Fixing bug in MaterialCategory Service.
it shows the error messages when the importation is incorrect.
This commit is contained in:
parent
af1aa94a31
commit
1cb4401a44
2 changed files with 17 additions and 9 deletions
|
|
@ -22,7 +22,7 @@ package org.navalplanner.business.materials.daos;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
|
||||
|
|
@ -72,14 +72,22 @@ public class MaterialCategoryDAO extends IntegrationEntityDAO<MaterialCategory>
|
|||
@Transactional(readOnly = true)
|
||||
public MaterialCategory findUniqueByName(String name)
|
||||
throws InstanceNotFoundException {
|
||||
Criteria criteria = getSession().createCriteria(MaterialCategory.class);
|
||||
criteria.add(Restrictions.eq("name", name).ignoreCase());
|
||||
|
||||
List<MaterialCategory> list = criteria.list();
|
||||
if (list.size() != 1) {
|
||||
throw new InstanceNotFoundException(name, MaterialCategory.class.getName());
|
||||
if (StringUtils.isBlank(name)) {
|
||||
throw new InstanceNotFoundException(null, getEntityClass()
|
||||
.getName());
|
||||
}
|
||||
|
||||
MaterialCategory materialCategory = (MaterialCategory) getSession()
|
||||
.createCriteria(MaterialCategory.class).add(
|
||||
Restrictions.eq("name", name.trim()).ignoreCase())
|
||||
.uniqueResult();
|
||||
|
||||
if (materialCategory == null) {
|
||||
throw new InstanceNotFoundException(name, getEntityClass().getName());
|
||||
} else {
|
||||
return materialCategory;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ public class MaterialCategory extends IntegrationEntity {
|
|||
return true;
|
||||
}
|
||||
|
||||
@AssertTrue
|
||||
@AssertTrue(message = "There are repeated material category codes")
|
||||
public boolean checkConstraintNonRepeatedMaterialCategoryCodes() {
|
||||
Set<MaterialCategory> allSubcategories = getAllSubcategories();
|
||||
allSubcategories.add(this);
|
||||
|
|
@ -244,7 +244,7 @@ public class MaterialCategory extends IntegrationEntity {
|
|||
return result;
|
||||
}
|
||||
|
||||
@AssertTrue
|
||||
@AssertTrue(message = "There are repeated material codes")
|
||||
public boolean checkConstraintNonRepeatedMaterialCodes() {
|
||||
Set<Material> allMaterials = getAllMaterials();
|
||||
return getFirstRepeatedCode(allMaterials) == null;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue