From cbc7c3c16982815def713259a37217a397091ea3 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 30 Jan 2013 10:43:25 +0100 Subject: [PATCH] jira-integration: Add checkings to prevent remove or disable type of work hours for JIRA connector FEA: ItEr77S16JiraAndTimConnectorContributionIntegration --- .../costcategories/daos/TypeOfWorkHoursDAO.java | 12 ++++++++++++ .../costcategories/entities/TypeOfWorkHours.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/libreplan-business/src/main/java/org/libreplan/business/costcategories/daos/TypeOfWorkHoursDAO.java b/libreplan-business/src/main/java/org/libreplan/business/costcategories/daos/TypeOfWorkHoursDAO.java index f20dae7f5..59573128c 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/costcategories/daos/TypeOfWorkHoursDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/costcategories/daos/TypeOfWorkHoursDAO.java @@ -149,6 +149,7 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO checkHasHourCost(type); checkHasWorkReportLine(type); checkIsPersonalTimesheetsTypeOfWorkHours(type); + checkIsJiraConnectorTypeOfWorkHours(type); } private void checkHasWorkReportLine(TypeOfWorkHours type) { @@ -192,4 +193,15 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO return c.uniqueResult() != null; } + private void checkIsJiraConnectorTypeOfWorkHours(TypeOfWorkHours type) { + Configuration configuration = configurationDAO.getConfiguration(); + if (configuration.getJiraConfiguration() + .getJiraConnectorTypeOfWorkHours().getId().equals(type.getId())) { + throw ValidationException + .invalidValue( + "Cannot delete the type of work hours. It is configured as type of work hours for JIRA connector.", + type); + } + } + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/costcategories/entities/TypeOfWorkHours.java b/libreplan-business/src/main/java/org/libreplan/business/costcategories/entities/TypeOfWorkHours.java index 1f8c5bbb5..f26d72b22 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/costcategories/entities/TypeOfWorkHours.java +++ b/libreplan-business/src/main/java/org/libreplan/business/costcategories/entities/TypeOfWorkHours.java @@ -165,4 +165,18 @@ public class TypeOfWorkHours extends IntegrationEntity implements IHumanIdentifi return name; } + @AssertTrue(message = "type of work hours for JIRA connector cannot be disabled") + public boolean checkJiraConnectorTypeOfWorkHoursNotDisabled() { + if (!isNewObject() && !getEnabled()) { + TypeOfWorkHours typeOfWorkHours = Registry.getConfigurationDAO() + .getConfiguration().getJiraConfiguration() + .getJiraConnectorTypeOfWorkHours(); + if (typeOfWorkHours.getId().equals(getId())) { + return false; + } + } + + return true; + } + }