Added default data for TypeOfWorkHours

FEA: ItEr75S29DefaultData
This commit is contained in:
Ignacio Diaz Teijido 2011-11-03 17:17:16 +01:00 committed by Manuel Rego Casasnovas
parent 879ab03d59
commit 90dfef1d6a
5 changed files with 159 additions and 0 deletions

View file

@ -46,6 +46,8 @@ public interface ITypeOfWorkHoursDAO extends
boolean existsByCode(TypeOfWorkHours typeOfWorkHours);
boolean existsByName(TypeOfWorkHours typeOfWorkHours);
boolean existsTypeWithCodeInAnotherTransaction(String code);
List<TypeOfWorkHours> findActive();

View file

@ -167,4 +167,11 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
}
}
@Override
public boolean existsByName(TypeOfWorkHours typeOfWorkHours) {
Criteria c = getSession().createCriteria(TypeOfWorkHours.class).add(
Restrictions.eq("name", typeOfWorkHours.getName()));
return c.uniqueResult() != null;
}
}

View file

@ -0,0 +1,32 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2011 CafédeRed Solutions, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.libreplan.business.costcategories.entities;
import org.libreplan.business.IDataBootstrap;
/**
* Interface for {@link TypeOfWorkHoursBootstrap}.
*
* @author Ignacio Díaz Teijido <ignacio.diaz@cafedered.com>
*/
public interface ITypeOfWorkHoursBootstrap extends IDataBootstrap {
void loadRequiredData();
}

View file

@ -0,0 +1,56 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2011 CafédeRed Solutions, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.libreplan.business.costcategories.entities;
import java.math.BigDecimal;
/**
* Defines the default {@link TypeOfWorkHours}.
*
* @author Ignacio Díaz Teijido <ignacio.diaz@cafedered.com>
*/
public enum PredefinedTypeOfWorkHours {
DEFAULT("Default", 30), OVERTIME("Overtime", 50);
private TypeOfWorkHours typeOfWorkHours;
private PredefinedTypeOfWorkHours(String name, double price) {
typeOfWorkHours = TypeOfWorkHours.create();
typeOfWorkHours.setName(name);
typeOfWorkHours.setDefaultPrice(new BigDecimal(price).setScale(2));
}
public TypeOfWorkHours getTypeOfWorkHours() {
return typeOfWorkHours;
}
public static boolean contains(TypeOfWorkHours typeOfWorkHours) {
PredefinedTypeOfWorkHours[] types = PredefinedTypeOfWorkHours.values();
for (PredefinedTypeOfWorkHours each : types) {
if (each.getTypeOfWorkHours().getName()
.equals(typeOfWorkHours.getName())) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,62 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2011 CafédeRed Solutions, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.libreplan.business.costcategories.entities;
import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.costcategories.daos.ITypeOfWorkHoursDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Creates the default {@link TypeOfWorkHours}.
*
* @author Ignacio Díaz Teijido <ignacio.diaz@cafedered.com>
*/
@Component
@Scope("singleton")
public class TypeOfWorkHoursBootstrap implements ITypeOfWorkHoursBootstrap {
@Autowired
private ITypeOfWorkHoursDAO typeOfWorkHoursDAO;
@Autowired
private IEntitySequenceDAO entitySequenceDAO;
@Override
@Transactional
public void loadRequiredData() {
for (PredefinedTypeOfWorkHours predefinedTypeOfWorkHours : PredefinedTypeOfWorkHours
.values()) {
TypeOfWorkHours typeOfWorkHours = predefinedTypeOfWorkHours
.getTypeOfWorkHours();
if (!typeOfWorkHoursDAO.existsByName(typeOfWorkHours)) {
typeOfWorkHours.setCodeAutogenerated(true);
typeOfWorkHours
.setCode(entitySequenceDAO
.getNextEntityCodeWithoutTransaction(EntityNameEnum.WORK_HOURS_TYPE));
typeOfWorkHoursDAO.save(typeOfWorkHours);
}
}
}
}