public async Task <ActionResult <RepoCrawlingJob> > PostRepoCrawlingJob(RepoCrawlingJob job) { if (job == null) { return(BadRequest()); } if (job.Repository == null) { return(BadRequest("missing repository ID.")); } var repository = _context.Repositories.Find(job.Repository.ID); if (repository == null) { return(BadRequest("invalid repository ID.")); } if (_context.RepoCrawlingJobs.Any( x => (x.Status == State.Queued || x.Status == State.Running) && x.Repository.ID == repository.ID)) { return(BadRequest($"The repository {repository.ID} is already set to be crawled.")); } job.Repository = repository; job.Status = default; _context.RepoCrawlingJobs.Add(job); await _context.SaveChangesAsync().ConfigureAwait(false); _queue.Enqueue(job.ID); return(CreatedAtAction("GetRepoCrawlingJob", new { id = job.ID }, job)); }
public async Task <IActionResult> PutToolRepoAssociation(int id, ToolRepoAssociation toolRepoAssociation) { if (id != toolRepoAssociation.ID) { return(BadRequest()); } _context.Entry(toolRepoAssociation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToolRepoAssociationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutRepo([FromRoute] int id, [FromBody] Repository repository) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != repository.ID) { return(BadRequest()); } _context.Entry(repository).State = EntityState.Modified; try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateConcurrencyException) { if (!RepoExists(id)) { return(NotFound()); } else { throw; } } return(Ok(repository)); }
public async Task <IActionResult> PutCitation(int id, Citation citation) { if (id != citation.ID) { return(BadRequest()); } _context.Entry(citation).State = EntityState.Modified; try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateConcurrencyException) { if (!CitationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task<IActionResult> PutTool([FromRoute] int id, [FromBody] Tool DataItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != DataItem.ID) { return BadRequest(); } _context.Entry(DataItem).State = EntityState.Modified; try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateConcurrencyException) { if (!ToolExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task <IActionResult> PutService([FromRoute] int id, [FromBody] Service service) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != service.ID) { return(BadRequest()); } _context.Entry(service).State = EntityState.Modified; try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateConcurrencyException) { if (!ServiceExists(id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetService", new { id = service.ID }, service)); }
public async Task <ActionResult <LiteratureCrawlingJob> > PostLiteratureCrawlingJob(LiteratureCrawlingJob job) { if (job == null) { return(BadRequest()); } if (job.ScanAllPublications == false && job.Publications == null) { return(BadRequest( "No publications to scan are provided; either set " + "`ScanAllPublications = true` or provide a list " + "of publications to scan.")); } if (job.ScanAllPublications == true) { if (_context.LiteratureCrawlingJobs.Any( x => x.ScanAllPublications == true && (x.Status == State.Queued || x.Status == State.Running))) { return(BadRequest($"A job for scanning all the publication is already set.")); } job.Publications = null; } else { var publications = new List <Publication>(); foreach (var publication in job.Publications) { var p = _context.Publications.Find(publication.ID); if (p != null) { publications.Add(p); } } if (publications.Count == 0) { return(BadRequest("No valid publication(s) ID.")); } job.Publications = publications; var currentActiveJobs = _context.LiteratureCrawlingJobs.Where( x => x.Status == State.Queued || x.Status == State.Running); foreach (var activeJob in currentActiveJobs) { if (activeJob.Publications != null && AreListsEqual(activeJob.Publications, job.Publications)) { return(BadRequest( $"The active job {activeJob.ID} has the " + $"same list of publications as the request.")); } } } _context.LiteratureCrawlingJobs.Add(job); await _context.SaveChangesAsync().ConfigureAwait(false); Queue.Enqueue(job.ID); return(CreatedAtAction("GetLiteratureCrawlingJob", new { id = job.ID }, job)); }