Commit 3f940232 by Harsh Shah

Bugfix: Candidate can apply for same job multiple times if application not yet…

Bugfix: Candidate can apply for same job multiple times if application not yet saved and opened in new tab.
parent 3b3133a4
......@@ -1871,6 +1871,8 @@ public abstract class BaseJobApplication extends BaseBusinessClass
.search (transaction);
}
public abstract boolean filterCandidateJob(Candidate Candidate, Job Job) throws StorageException;
public static SearchCandidateJob SearchByCandidateJob () { return new SearchCandidateJob (); }
public static class SearchCandidateJob extends SearchObject<JobApplication>
......@@ -1939,6 +1941,8 @@ public abstract class BaseJobApplication extends BaseBusinessClass
public JobApplication search (ObjectTransaction transaction) throws StorageException
{
Candidate Candidate = (Candidate)criteria.get ("Candidate");
Job Job = (Job)criteria.get ("Job");
BaseBusinessClass[] results = super.search (transaction, REFERENCE_JobApplication, SEARCH_CandidateJob, criteria);
......@@ -1947,9 +1951,31 @@ public abstract class BaseJobApplication extends BaseBusinessClass
{
JobApplication aResult = (JobApplication)bbcResult;
// Check in case in memory objects should be excluded
if (!aResult.filterCandidateJob(Candidate, Job) || !filterAndsInMemory (aResult))
{
continue;
}
typedResults.add (aResult);
}
// Check in memory objects for matches
for (BaseBusinessClass bbcInMemory : transaction.getObjectsToStore ())
{
if (bbcInMemory instanceof JobApplication)
{
JobApplication aInMemory = (JobApplication)bbcInMemory;
if (!aInMemory.filterCandidateJob(Candidate, Job) || !filterAndsInMemory (aInMemory))
{
continue;
}
typedResults.add (aInMemory);
}
}
return (JobApplication)singletonResult(ObjstoreUtils.removeDeleted(transaction, typedResults).toArray(new BaseBusinessClass[0]), "JobApplication", "");
}
......
......@@ -2,10 +2,11 @@ package performa.orm;
import java.util.*;
import oneit.logging.LoggingArea;
import oneit.objstore.StorageException;
import oneit.objstore.*;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.objstore.rdbms.filters.IsNotNullFilter;
import oneit.objstore.rdbms.filters.NotEqualsFilter;
import oneit.utils.*;
import oneit.utils.filter.CollectionFilter;
import oneit.utils.filter.Filter;
import oneit.utils.math.NullArith;
......@@ -37,6 +38,21 @@ public class JobApplication extends BaseJobApplication
return jobApplication;
}
@Override
public void validate(ValidationContext context)
{
try
{
//Ideally should be managed with uniqueGroup, but uniqueGroup doesnt work without atleast 1 attribute
searchCandidateJob(getTransaction(), getCandidate(), getJob()); //It will throw RuntimeException when more than 1 record found.
}
catch(RuntimeException ex)
{
context.check(false, this, SINGLEREFERENCE_Job, "alreadyApplied");
}
super.validate(context);
}
public boolean createAssessmentCriteriaObjects() throws FieldException
{
......@@ -376,4 +392,10 @@ public class JobApplication extends BaseJobApplication
}
return remainingTime;
}
@Override
public boolean filterCandidateJob(Candidate candidate, Job job) throws StorageException
{
return (CollectionUtils.equals(candidate, getCandidate()) && CollectionUtils.equals(job, getJob()));
}
}
\ No newline at end of file
......@@ -23,7 +23,7 @@
<SEARCH type="All" paramFilter="tl_job_application.object_id is not null" orderBy="tl_job_application.object_id" />
<SEARCH type="CandidateJob" paramFilter="tl_job_application.object_id is not null" singleton="TRUE">
<SEARCH type="CandidateJob" paramFilter="tl_job_application.object_id is not null" singleton="TRUE" checkTXObjects="TRUE">
<PARAM name="Candidate" type="Candidate" transform="Candidate.getObjectID()" paramFilter="candidate_id = ${Candidate} " />
<PARAM name="Job" type="Job" transform="Job.getObjectID()" paramFilter="job_id = ${Job}" />
</SEARCH>
......
......@@ -2,3 +2,4 @@
#completeCulture = Please complete the culture assessment.
#emailExists = An account already exists with this email address.
#emailSent = A verification email has been sent to you. Please check your email :).
#alreadyApplied = You have already applied for this job.
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_job_application" indexName="idx_tl_job_application_CandidateJob" isUnique="true"><column name="candidate_id"/><column name="job_id"/></NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment