ItEr20S07CUIntroducionAvanceUnidadeTraballoItEr19S12: Add default types of advances when startup the database.

This commit is contained in:
Susana Montes Pedreira 2009-08-04 11:12:01 +02:00 committed by Óscar González Fernández
parent fbed099f01
commit e08a34793c
4 changed files with 65 additions and 7 deletions

View file

@ -1,7 +1,9 @@
package org.navalplanner.business.advance.daos;
import org.navalplanner.business.common.daos.GenericDAOHibernate;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.advance.entities.AdvanceType;
import org.navalplanner.business.common.daos.GenericDAOHibernate;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
@ -12,5 +14,16 @@ import org.springframework.stereotype.Repository;
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class AdvanceTypeDAO extends GenericDAOHibernate<AdvanceType, Long> implements IAdvanceTypeDAO{
public class AdvanceTypeDAO extends GenericDAOHibernate<AdvanceType, Long>
implements IAdvanceTypeDAO {
public boolean existsNameAdvanceType(String unitName) {
try {
return getSession().createCriteria(AdvanceType.class).add(
Restrictions.eq("unitName", unitName)).uniqueResult() != null;
} catch (HibernateException e) {
throw convertHibernateAccessException(e);
}
}
}

View file

@ -1,7 +1,7 @@
package org.navalplanner.business.advance.daos;
import org.navalplanner.business.common.daos.IGenericDAO;
import org.navalplanner.business.advance.entities.AdvanceType;
import org.navalplanner.business.common.daos.IGenericDAO;
/**
* Contract for {@link AdvanceTypeDao}
@ -9,4 +9,5 @@ import org.navalplanner.business.advance.entities.AdvanceType;
*/
public interface IAdvanceTypeDAO extends IGenericDAO<AdvanceType, Long>{
public boolean existsNameAdvanceType(String unitName);
}

View file

@ -40,10 +40,10 @@ public class AdvanceType {
boolean updatable, BigDecimal precision, boolean active) {
this.unitName = unitName;
this.defaultMaxValue = defaultMaxValue;
this.defaultMaxValue.setScale(2);
this.defaultMaxValue.setScale(2, BigDecimal.ROUND_HALF_UP);
this.updatable = updatable;
this.precision = precision;
this.precision.setScale(4);
this.precision.setScale(4, BigDecimal.ROUND_HALF_UP);
this.active = active;
}
@ -65,7 +65,7 @@ public class AdvanceType {
public void setDefaultMaxValue(BigDecimal defaultMaxValue) {
this.defaultMaxValue = defaultMaxValue;
this.defaultMaxValue.setScale(2);
this.defaultMaxValue.setScale(2, BigDecimal.ROUND_HALF_UP);
}
public BigDecimal getDefaultMaxValue() {
@ -82,7 +82,7 @@ public class AdvanceType {
public void setPrecision(BigDecimal precision) {
this.precision = precision;
this.precision.setScale(4);
this.precision.setScale(4, BigDecimal.ROUND_HALF_UP);
}
public BigDecimal getPrecision() {

View file

@ -0,0 +1,44 @@
package org.navalplanner.web.bootstrap;
import java.math.BigDecimal;
import org.navalplanner.business.IDataBootstrap;
import org.navalplanner.business.advance.daos.IAdvanceTypeDAO;
import org.navalplanner.business.advance.entities.AdvanceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
@Scope("singleton")
public class DefaultAdvanceTypesBootstrapListener implements IDataBootstrap {
@Autowired
private IAdvanceTypeDAO advanceTypeDAO;
@Transactional
@Override
public void loadRequiredData() {
if (!advanceTypeDAO.existsNameAdvanceType("porcentaxe")) {
BigDecimal defaultMaxValue = new BigDecimal(100).setScale(2,
BigDecimal.ROUND_HALF_UP);
BigDecimal precision = new BigDecimal(0.01).setScale(4,
BigDecimal.ROUND_HALF_UP);
AdvanceType advanceTypePorcentaxe = new AdvanceType("porcentaxe",
defaultMaxValue, false, precision, true);
advanceTypeDAO.save(advanceTypePorcentaxe);
}
if (!advanceTypeDAO.existsNameAdvanceType("unidades")) {
BigDecimal defaultMaxValue = new BigDecimal(Integer.MAX_VALUE)
.setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal precision = new BigDecimal(1).setScale(4,
BigDecimal.ROUND_HALF_UP);
AdvanceType advanceTypeUnidades = new AdvanceType("unidades",
defaultMaxValue, false, precision, true);
advanceTypeDAO.save(advanceTypeUnidades);
}
}
}