ItEr39S17CUImportacionOrganizacionsTraballo: Created bootstrat to add default material categories.
* For the moment created just one material category "Imported materials without category".
This commit is contained in:
parent
e16fbc8da8
commit
9ee01d4c41
3 changed files with 149 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.materials.entities;
|
||||
|
||||
import org.navalplanner.business.IDataBootstrap;
|
||||
|
||||
/**
|
||||
* Contratct for {@link MaterialCategory}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IMaterialCategoryBootstrap extends IDataBootstrap {
|
||||
|
||||
void loadRequiredData();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.materials.entities;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
|
||||
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 CalendarExceptionType}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class MaterialCategoryBootstrap implements IMaterialCategoryBootstrap {
|
||||
|
||||
@Autowired
|
||||
private IMaterialCategoryDAO materialCategoryDAO;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void loadRequiredData() {
|
||||
for (PredefinedMaterialCategories predefinedMaterialCategory : PredefinedMaterialCategories
|
||||
.values()) {
|
||||
if (!materialCategoryDAO
|
||||
.existsMaterialCategoryWithNameInAnotherTransaction(predefinedMaterialCategory
|
||||
.getName())) {
|
||||
materialCategoryDAO.save(predefinedMaterialCategory
|
||||
.createMaterialCategory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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.navalplanner.business.materials.entities;
|
||||
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the default {@link MaterialCategory}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public enum PredefinedMaterialCategories {
|
||||
|
||||
IMPORTED_MATERIALS_WITHOUT_CATEGORY("Imported materials without category");
|
||||
|
||||
private final String name;
|
||||
|
||||
private PredefinedMaterialCategories(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public MaterialCategory createMaterialCategory() {
|
||||
return MaterialCategory.create(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public MaterialCategory getMaterialCategory() {
|
||||
try {
|
||||
return Registry.getMaterialCategoryDAO()
|
||||
.findUniqueByNameInAnotherTransaction(name);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue