jira and tim-connector: Constraints for JobSchedulerConfiguration
This commit is contained in:
parent
131941ea6f
commit
94f3763e32
4 changed files with 108 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ import org.libreplan.business.calendars.daos.ICalendarExceptionTypeDAO;
|
|||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.libreplan.business.common.daos.IEntitySequenceDAO;
|
||||
import org.libreplan.business.common.daos.IJobSchedulerConfigurationDAO;
|
||||
import org.libreplan.business.costcategories.daos.ICostCategoryDAO;
|
||||
import org.libreplan.business.costcategories.daos.IHourCostDAO;
|
||||
import org.libreplan.business.costcategories.daos.IResourcesCostCategoryAssignmentDAO;
|
||||
|
|
@ -45,6 +46,7 @@ import org.libreplan.business.materials.daos.IUnitTypeDAO;
|
|||
import org.libreplan.business.orders.daos.IHoursGroupDAO;
|
||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||
import org.libreplan.business.orders.daos.IOrderElementDAO;
|
||||
import org.libreplan.business.orders.daos.IOrderSyncInfoDAO;
|
||||
import org.libreplan.business.planner.daos.ITaskElementDAO;
|
||||
import org.libreplan.business.qualityforms.daos.IQualityFormDAO;
|
||||
import org.libreplan.business.resources.daos.ICriterionDAO;
|
||||
|
|
@ -207,6 +209,12 @@ public class Registry {
|
|||
@Autowired
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
@Autowired
|
||||
private IOrderSyncInfoDAO orderSyncInfoDAO;
|
||||
|
||||
@Autowired
|
||||
private IJobSchedulerConfigurationDAO jobSchedulerConfigurationDAO;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService transactionServiceDAO;
|
||||
|
||||
|
|
@ -387,4 +395,11 @@ public class Registry {
|
|||
return getInstance().connectorDAO;
|
||||
}
|
||||
|
||||
public static IOrderSyncInfoDAO getOrderSyncInfoDAO() {
|
||||
return getInstance().orderSyncInfoDAO;
|
||||
}
|
||||
|
||||
public static IJobSchedulerConfigurationDAO getJobSchedulerConfigurationDAO() {
|
||||
return getInstance().jobSchedulerConfigurationDAO;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,50 @@ import org.libreplan.business.common.entities.JobSchedulerConfiguration;
|
|||
public interface IJobSchedulerConfigurationDAO extends
|
||||
IGenericDAO<JobSchedulerConfiguration, Long> {
|
||||
|
||||
/**
|
||||
* Returns all {@link JobSchedulerConfiguration}
|
||||
*/
|
||||
List<JobSchedulerConfiguration> getAll();
|
||||
|
||||
/**
|
||||
* Searches and returns {@link JobSchedulerConfiguration} for the given
|
||||
* <code>connectorName</code>
|
||||
*
|
||||
* @param connectorName
|
||||
* the name of the connector
|
||||
*/
|
||||
List<JobSchedulerConfiguration> findByConnectorName(String connectorName);
|
||||
|
||||
/**
|
||||
* Searches and returns {@link JobSchedulerConfiguration} for the given
|
||||
* <code>jobGroup</code> and <code>jobName</code>
|
||||
*
|
||||
* @param jobGroup
|
||||
* @param jobName
|
||||
*/
|
||||
JobSchedulerConfiguration findByJobGroupAndJobName(String jobGroup,
|
||||
String jobName);
|
||||
|
||||
/**
|
||||
* Returns true if there exists other @{link JobSchedulerConfiguration} with
|
||||
* the same <code>{@link JobSchedulerConfiguration#getJobGroup()}</code> and
|
||||
* <code>{@link JobSchedulerConfiguration#getJobName()</code>
|
||||
*
|
||||
* @param jobSchedulerConfiguration
|
||||
* the <code>{@link JobSchedulerConfiguration}</code>
|
||||
*/
|
||||
boolean existsByJobGroupAndJobNameAnotherTransaction(
|
||||
JobSchedulerConfiguration jobSchedulerConfiguration);
|
||||
|
||||
/**
|
||||
* Returns unique {@link JobSchedulerConfiguration} for the specified
|
||||
* <code>JobGroup</code> and <code>JobName</code>
|
||||
*
|
||||
* @param jobGroup
|
||||
* the jobGroup
|
||||
* @param jobName
|
||||
* the jobName
|
||||
*/
|
||||
JobSchedulerConfiguration findUniqueByJobGroupAndJobNameAnotherTransaction(
|
||||
String jobGroup, String jobName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ import java.util.List;
|
|||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.libreplan.business.common.entities.JobSchedulerConfiguration;
|
||||
import org.libreplan.business.orders.entities.OrderSyncInfo;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -66,4 +68,33 @@ public class JobSchedulerConfigurationDAO extends
|
|||
return ((List<JobSchedulerConfiguration>) c.list());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByJobGroupAndJobNameAnotherTransaction(
|
||||
JobSchedulerConfiguration jobSchedulerConfiguration) {
|
||||
return existsOtherJobByGroupAndName(jobSchedulerConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if other {@link JobSchedulerConfiguration} which is the same
|
||||
* as the given <code>{@link OrderSyncInfo} already exists
|
||||
*
|
||||
* @param jobSchedulerConfiguration
|
||||
* the {@link JobSchedulerConfiguration}
|
||||
*/
|
||||
private boolean existsOtherJobByGroupAndName(
|
||||
JobSchedulerConfiguration jobSchedulerConfiguration) {
|
||||
JobSchedulerConfiguration found = findByJobGroupAndJobName(
|
||||
jobSchedulerConfiguration.getJobGroup(),
|
||||
jobSchedulerConfiguration.getJobName());
|
||||
return found != null && found != jobSchedulerConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public JobSchedulerConfiguration findUniqueByJobGroupAndJobNameAnotherTransaction(
|
||||
String jobGroup, String jobName) {
|
||||
return findByJobGroupAndJobName(jobGroup, jobName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,13 @@
|
|||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.libreplan.business.common.BaseEntity;
|
||||
import org.libreplan.business.common.IHumanIdentifiable;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.common.daos.IJobSchedulerConfigurationDAO;
|
||||
|
||||
/**
|
||||
* JobSchedulerConfiguration entity, represents parameters for the jobs to be
|
||||
|
|
@ -115,4 +119,22 @@ public class JobSchedulerConfiguration extends BaseEntity implements
|
|||
public String getHumanId() {
|
||||
return jobGroup == null ? "" : jobGroup;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "job group and name are already being used")
|
||||
public boolean checkConstraintUniqueJobGroupAndName() {
|
||||
if (StringUtils.isBlank(jobGroup) && StringUtils.isBlank(jobName)) {
|
||||
return true;
|
||||
}
|
||||
IJobSchedulerConfigurationDAO jobSchedulerConfigurationDAO = Registry
|
||||
.getJobSchedulerConfigurationDAO();
|
||||
if (isNewObject()) {
|
||||
return !jobSchedulerConfigurationDAO
|
||||
.existsByJobGroupAndJobNameAnotherTransaction(this);
|
||||
} else {
|
||||
JobSchedulerConfiguration found = jobSchedulerConfigurationDAO
|
||||
.findUniqueByJobGroupAndJobNameAnotherTransaction(jobGroup,
|
||||
jobName);
|
||||
return found == null || found.getId().equals(getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue