From 66444c8aa2117747d86fe00854b4314c192cc90e Mon Sep 17 00:00:00 2001 From: JoaoRoxo Date: Fri, 23 Oct 2015 14:14:00 +0000 Subject: [PATCH] Added support for a default social security number that skips duplicate validation. --- .../FenixEduAcademicConfiguration.java | 5 +++++ .../domain/organizationalStructure/Party.java | 21 ++++++++++++------- .../PartySocialSecurityNumber.java | 10 ++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/fenixedu/academic/FenixEduAcademicConfiguration.java b/src/main/java/org/fenixedu/academic/FenixEduAcademicConfiguration.java index 7e6998f267b..9ae8e112e58 100644 --- a/src/main/java/org/fenixedu/academic/FenixEduAcademicConfiguration.java +++ b/src/main/java/org/fenixedu/academic/FenixEduAcademicConfiguration.java @@ -38,6 +38,11 @@ public interface ConfigurationProperties { @ConfigurationProperty(key = "ciist.sms.shouldRun") public Boolean getCIISTSMSShouldRun(); + @ConfigurationProperty( + key = "default.social.security.number", + description = "Identifies the default social security number to be used in the country (e.g. for Portugal it is 999999990)") + public String getDefaultSocialSecurityNumber(); + @ConfigurationProperty(key = "generic.application.email.confirmation.link", defaultValue = "http://localhost:8080/fenix/publico/genericApplications.do?method=confirmEmail&confirmationCode=") public String getGenericApplicationEmailConfirmationLink(); diff --git a/src/main/java/org/fenixedu/academic/domain/organizationalStructure/Party.java b/src/main/java/org/fenixedu/academic/domain/organizationalStructure/Party.java index 1b7a534238f..f25bfd4232d 100755 --- a/src/main/java/org/fenixedu/academic/domain/organizationalStructure/Party.java +++ b/src/main/java/org/fenixedu/academic/domain/organizationalStructure/Party.java @@ -32,6 +32,7 @@ import org.apache.commons.collections.comparators.ComparatorChain; import org.apache.commons.lang.StringUtils; +import org.fenixedu.academic.FenixEduAcademicConfiguration; import org.fenixedu.academic.domain.CompetenceCourse; import org.fenixedu.academic.domain.Country; import org.fenixedu.academic.domain.DomainObjectUtil; @@ -462,16 +463,20 @@ public void setSocialSecurityNumber(String socialSecurityNumber) { return; } - final Party party = PartySocialSecurityNumber.readPartyBySocialSecurityNumber(socialSecurityNumber); - if (party != null && party != this) { - throw new DomainException("error.party.existing.contributor.number"); - } else { - if (getPartySocialSecurityNumber() != null) { - getPartySocialSecurityNumber().setSocialSecurityNumber(socialSecurityNumber); - } else { - new PartySocialSecurityNumber(this, socialSecurityNumber); + String defaultSocialSecurityNumber = + FenixEduAcademicConfiguration.getConfiguration().getDefaultSocialSecurityNumber(); + if (defaultSocialSecurityNumber == null || !defaultSocialSecurityNumber.equals(socialSecurityNumber)) { + final Party party = PartySocialSecurityNumber.readPartyBySocialSecurityNumber(socialSecurityNumber); + if (party != null && party != this) { + throw new DomainException("error.party.existing.contributor.number"); } } + + if (getPartySocialSecurityNumber() != null) { + getPartySocialSecurityNumber().setSocialSecurityNumber(socialSecurityNumber); + } else { + new PartySocialSecurityNumber(this, socialSecurityNumber); + } } } diff --git a/src/main/java/org/fenixedu/academic/domain/organizationalStructure/PartySocialSecurityNumber.java b/src/main/java/org/fenixedu/academic/domain/organizationalStructure/PartySocialSecurityNumber.java index e8e6656967d..1f0ac95a871 100644 --- a/src/main/java/org/fenixedu/academic/domain/organizationalStructure/PartySocialSecurityNumber.java +++ b/src/main/java/org/fenixedu/academic/domain/organizationalStructure/PartySocialSecurityNumber.java @@ -18,6 +18,7 @@ */ package org.fenixedu.academic.domain.organizationalStructure; +import org.fenixedu.academic.FenixEduAcademicConfiguration; import org.fenixedu.academic.domain.exceptions.DomainException; import org.fenixedu.bennu.core.domain.Bennu; @@ -43,9 +44,12 @@ private void checkParameters(final Party party, final String socialSecurityNumbe throw new DomainException("error.PartySocialSecurityNumber.invalid.socialSecurityNumber"); } - for (final PartySocialSecurityNumber securityNumber : Bennu.getInstance().getPartySocialSecurityNumbersSet()) { - if (securityNumber != this && securityNumber.hasSocialSecurityNumber(socialSecurityNumber)) { - throw new DomainException("error.PartySocialSecurityNumber.number.already.exists"); + String defaultSocialSecurityNumber = FenixEduAcademicConfiguration.getConfiguration().getDefaultSocialSecurityNumber(); + if (defaultSocialSecurityNumber == null || !defaultSocialSecurityNumber.equals(socialSecurityNumber)) { + for (final PartySocialSecurityNumber securityNumber : Bennu.getInstance().getPartySocialSecurityNumbersSet()) { + if (securityNumber != this && securityNumber.hasSocialSecurityNumber(socialSecurityNumber)) { + throw new DomainException("error.PartySocialSecurityNumber.number.already.exists"); + } } } }