@Override public synchronized JobMetadata register(String name, Person owner) { Long ownerId = null; if (owner != null && owner.getId() != null) ownerId = owner.getId(); JobMetadataImpl job = new JobMetadataImpl(name, ownerId); jobs.add(job); _prune(); return job; }
/** * Generate a new error report. * * @param user The user who encountered the error. * @param where Where the error occured. * @param exception The exception encountered. */ public ErrorReportImpl(Person user, String where, Throwable exception) { this.when = new Date(); if (user != null) { this.who = String.format( "%s (%d: %s)", user.getFormattedName(NameFormat.FIRST_LAST), user.getId(), user.getEmail()); } else { this.who = null; } this.where = where; if (exception != null) this.what = exception.getClass().getName(); else this.what = null; this.trace = ExceptionUtils.getStackTrace(exception); }
/** Test that an admin can change the submission assignee */ @Test public void testChangeAssignedTo() { context.turnOffAuthorization(); Person person = personRepo.findPersonByEmail("*****@*****.**"); Person newPerson = personRepo.createPerson("jdoe", "*****@*****.**", "John", "Doe", RoleType.REVIEWER); newPerson.save(); Submission submission = subRepo.createSubmission(person); submission.setAssignee(person); submission.save(); Long id = submission.getId(); Long personId = newPerson.getId(); assertEquals(submission.getAssignee().getCurrentEmailAddress(), "*****@*****.**"); JPA.em().getTransaction().commit(); JPA.em().clear(); JPA.em().getTransaction().begin(); LOGIN(); String UPDATE_URL = Router.reverse("ViewTab.changeAssignedTo").url; Map<String, String> params = new HashMap<String, String>(); params.put("id", id.toString()); params.put("assignee", personId.toString()); params.put("special_value", ""); Response response = POST(UPDATE_URL, params); assertStatus(302, response); submission = subRepo.findSubmission(id); newPerson = personRepo.findPerson(personId); assertEquals(submission.getAssignee().getCurrentEmailAddress(), "*****@*****.**"); submission.delete(); newPerson.delete(); context.restoreAuthorization(); }
@Override public synchronized List<JobMetadata> findJobsByOwner(Person owner) { if (owner == null || owner.getId() == null) throw new IllegalArgumentException( "Unable to find background operations from a specific owner without the owner specified."); List<JobMetadata> found = new ArrayList<JobMetadata>(); Long personId = owner.getId(); for (JobMetadata job : jobs) { if (personId.equals(job.getOwnerId())) { found.add(job); } } Collections.reverse(found); return found; }
/** * Clean up any submissions and people that we created for this test. Then rollback the * transaction. */ @After public void cleanup() { for (Submission sub : subs) { subRepo.findSubmission(sub.getId()).delete(); } personRepo.findPerson(person.getId()).delete(); context.logout(); indexer.rollback(); JPA.em().getTransaction().commit(); JPA.em().getTransaction().begin(); }
/** * This method produces the common part of the query handle the filter search clauses. * * @param andQuery The existing and-based query * @param filter The filter search paramaters. * @param submissions Whether this is for submissions or action logs */ public void buildQuery(BooleanQuery andQuery, SearchFilter filter, boolean submissions) { QueryParser parser = new QueryParser(indexer.version, "searchText", indexer.standardAnalyzer); // Include Submission filter if (filter.getIncludedSubmissions().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (Submission sub : filter.getIncludedSubmissions()) { orQuery.add( new TermQuery(new Term("subId", NumericUtils.longToPrefixCoded(sub.getId()))), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Include Log filter if (filter.getIncludedActionLogs().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (ActionLog log : filter.getIncludedActionLogs()) { orQuery.add( new TermQuery(new Term("logId", NumericUtils.longToPrefixCoded(log.getId()))), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Exclude Submission filter for (Submission sub : filter.getExcludedSubmissions()) { andQuery.add( new TermQuery(new Term("subId", NumericUtils.longToPrefixCoded(sub.getId()))), Occur.MUST_NOT); } // Exclude Log filter for (ActionLog log : filter.getExcludedActionLogs()) { andQuery.add( new TermQuery(new Term("logId", NumericUtils.longToPrefixCoded(log.getId()))), Occur.MUST_NOT); } // Search Text Filter if (filter.getSearchText().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String searchText : filter.getSearchText()) { try { // First try to interpret it as a complex lucene search string. orQuery.add(parser.parse(searchText), Occur.SHOULD); } catch (ParseException e) { // If that fails just fall back to a term query. orQuery.add(new TermQuery(new Term("searchText", searchText)), Occur.SHOULD); } } andQuery.add(orQuery, Occur.MUST); } // State Filter if (filter.getStates().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String stateName : filter.getStates()) { State state = stateManager.getState(stateName); orQuery.add(new TermQuery(new Term("state", state.getDisplayName())), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Assignee Filter if (filter.getAssignees().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (Person assignee : filter.getAssignees()) { long assigneeId = 0; if (assignee != null) assigneeId = assignee.getId(); orQuery.add( new TermQuery(new Term("searchAssigned", NumericUtils.longToPrefixCoded(assigneeId))), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Embargo Filter if (filter.getEmbargoTypes().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (EmbargoType embargo : filter.getEmbargoTypes()) { orQuery.add( new TermQuery( new Term("embargo", embargo.getName() + " " + embargo.getGuarantor().name())), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Graduation Semester Filter if (filter.getGraduationSemesters().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (Semester semester : filter.getGraduationSemesters()) { // We can't index it if it dosn't have a date. if (semester.year == null) continue; Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(Calendar.YEAR, semester.year); if (semester.month != null) { cal.set(Calendar.MONTH, semester.month); } orQuery.add( new TermQuery( new Term( "graduationSemester", NumericUtils.longToPrefixCoded(cal.getTimeInMillis()))), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Degree Filter if (filter.getDegrees().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String degree : filter.getDegrees()) { orQuery.add(new TermQuery(new Term("degree", degree)), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Department Filter if (filter.getDepartments().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String dept : filter.getDepartments()) { orQuery.add(new TermQuery(new Term("department", dept)), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Program Filter if (filter.getPrograms().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String program : filter.getPrograms()) { orQuery.add(new TermQuery(new Term("program", program)), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // College Filter if (filter.getColleges().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String college : filter.getColleges()) { orQuery.add(new TermQuery(new Term("college", college)), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Major Filter if (filter.getMajors().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String major : filter.getMajors()) { orQuery.add(new TermQuery(new Term("major", major)), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // Document Type Filter if (filter.getDocumentTypes().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (String docType : filter.getDocumentTypes()) { orQuery.add(new TermQuery(new Term("documentType", docType)), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } // UMI Release Filter if (filter.getUMIRelease() != null) { if (filter.getUMIRelease()) { andQuery.add(new TermQuery(new Term("umiRelease", "yes")), Occur.MUST); } else { andQuery.add(new TermQuery(new Term("umiRelease", "no")), Occur.MUST); } } // Date Range Filter if (filter.getDateRangeStart() != null || filter.getDateRangeEnd() != null) { long startTime = 0; if (filter.getDateRangeStart() != null) startTime = filter.getDateRangeStart().getTime(); long endTime = Long.MAX_VALUE; if (filter.getDateRangeEnd() != null) endTime = filter.getDateRangeEnd().getTime(); if (submissions) andQuery.add( NumericRangeQuery.newLongRange("submissionDate", startTime, endTime, true, true), Occur.MUST); else andQuery.add( NumericRangeQuery.newLongRange("lastEventTime", startTime, endTime, true, true), Occur.MUST); } // Custom Action Filter if (filter.getCustomActions().size() > 0) { BooleanQuery orQuery = new BooleanQuery(); for (CustomActionDefinition customAction : filter.getCustomActions()) { orQuery.add(new TermQuery(new Term("customAction", customAction.getLabel())), Occur.SHOULD); } andQuery.add(orQuery, Occur.MUST); } }