@Override
public QueryResult<Job> insert(Job job, long studyId, QueryOptions options) throws CatalogDBException {
long startTime = startQuery();
this.dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId);
List<Bson> filterList = new ArrayList<>();
filterList.add(Filters.eq(QueryParams.ID.key(), job.getId()));
filterList.add(Filters.eq(PRIVATE_STUDY_ID, studyId));
filterList.add(Filters.eq(QueryParams.STATUS_NAME.key(), Status.READY));
Bson bson = Filters.and(filterList);
QueryResult<Long> count = jobCollection.count(bson);
if (count.getResult().get(0) > 0) {
throw new CatalogDBException("Job { id: '" + job.getId() + "'} already exists.");
}
long jobId = getNewId();
job.setUid(jobId);
job.setStudyUid(studyId);
if (StringUtils.isEmpty(job.getUuid())) {
job.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.JOB));
}
Document jobObject = jobConverter.convertToStorageType(job);
if (StringUtils.isNotEmpty(job.getCreationDate())) {
jobObject.put(PRIVATE_CREATION_DATE, TimeUtils.toDate(job.getCreationDate()));
} else {
jobObject.put(PRIVATE_CREATION_DATE, TimeUtils.getDate());
}
jobObject.put(PERMISSION_RULES_APPLIED, Collections.emptyList());
jobCollection.insert(jobObject, null);
return endQuery("Create Job", startTime, get(jobId, filterOptions(options, FILTER_ROUTE_JOBS)));
}