ItEr20S07CUIntroducionAvanceUnidadeTraballoItEr19S12: Retrieving default types from enum.
This commit is contained in:
parent
4ec02f6b27
commit
e1efe3d7be
2 changed files with 37 additions and 21 deletions
|
|
@ -1,10 +1,7 @@
|
|||
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;
|
||||
|
|
@ -20,24 +17,10 @@ public class DefaultAdvanceTypesBootstrapListener implements IDataBootstrap {
|
|||
@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);
|
||||
for (PredefinedAdvancedTypes predefinedType : PredefinedAdvancedTypes.values()) {
|
||||
if (!advanceTypeDAO.existsNameAdvanceType(predefinedType.getTypeName())) {
|
||||
advanceTypeDAO.save(predefinedType.createType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package org.navalplanner.web.bootstrap;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.navalplanner.business.advance.entities.AdvanceType;
|
||||
|
||||
public enum PredefinedAdvancedTypes {
|
||||
PERCENTAGE("porcentaxe", new BigDecimal(100), new BigDecimal(0.01)), UNITS(
|
||||
"unidades", new BigDecimal(Integer.MAX_VALUE), new BigDecimal(1));
|
||||
|
||||
private PredefinedAdvancedTypes(String name, BigDecimal defaultMaxValue,
|
||||
BigDecimal precision) {
|
||||
this.name = name;
|
||||
this.defaultMaxValue = defaultMaxValue.setScale(4,
|
||||
BigDecimal.ROUND_HALF_UP);
|
||||
this.precision = precision.setScale(4, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
private final BigDecimal defaultMaxValue;
|
||||
|
||||
private final BigDecimal precision;
|
||||
|
||||
public AdvanceType createType() {
|
||||
return new AdvanceType(name, defaultMaxValue, false, precision, true);
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue