From 9ee01d4c41dd832037eb45e3030607ca51aac9ba Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 16 Dec 2009 17:38:42 +0100 Subject: [PATCH] ItEr39S17CUImportacionOrganizacionsTraballo: Created bootstrat to add default material categories. * For the moment created just one material category "Imported materials without category". --- .../entities/IMaterialCategoryBootstrap.java | 34 +++++++++++ .../entities/MaterialCategoryBootstrap.java | 56 ++++++++++++++++++ .../PredefinedMaterialCategories.java | 59 +++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/IMaterialCategoryBootstrap.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/MaterialCategoryBootstrap.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/PredefinedMaterialCategories.java diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/IMaterialCategoryBootstrap.java b/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/IMaterialCategoryBootstrap.java new file mode 100644 index 000000000..d33a4cd91 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/IMaterialCategoryBootstrap.java @@ -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 . + */ + +package org.navalplanner.business.materials.entities; + +import org.navalplanner.business.IDataBootstrap; + +/** + * Contratct for {@link MaterialCategory}. + * + * @author Manuel Rego Casasnovas + */ +public interface IMaterialCategoryBootstrap extends IDataBootstrap { + + void loadRequiredData(); + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/MaterialCategoryBootstrap.java b/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/MaterialCategoryBootstrap.java new file mode 100644 index 000000000..fe9229b1f --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/MaterialCategoryBootstrap.java @@ -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 . + */ + +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 + */ +@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()); + } + } + } + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/PredefinedMaterialCategories.java b/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/PredefinedMaterialCategories.java new file mode 100644 index 000000000..ddef15c59 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/materials/entities/PredefinedMaterialCategories.java @@ -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 . + */ + +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 + */ +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); + } + } + +} \ No newline at end of file