/** Test that an admin can change the custom action values. */ @Test public void testUpdateCustomActionsJSON() { context.turnOffAuthorization(); Person person = personRepo.findPersonByEmail("*****@*****.**"); Submission submission = subRepo.createSubmission(person); submission.setAssignee(person); submission.save(); Long id = submission.getId(); assertEquals(submission.getAssignee().getCurrentEmailAddress(), "*****@*****.**"); CustomActionDefinition actionDef = settingRepo.createCustomActionDefinition("Passed Classes", false).save(); Long actionId = actionDef.getId(); JPA.em().getTransaction().commit(); JPA.em().clear(); JPA.em().getTransaction().begin(); LOGIN(); String UPDATE_URL = Router.reverse("ViewTab.updateCustomActionsJSON").url; Map<String, String> params = new HashMap<String, String>(); params.put("id", id.toString()); params.put("action", actionId.toString()); params.put("value", "true"); Response response = POST(UPDATE_URL, params); assertIsOk(response); submission = subRepo.findSubmission(id); actionDef = settingRepo.findCustomActionDefinition(actionId); assertTrue(submission.getCustomAction(actionDef).getValue()); submission.delete(); actionDef.delete(); context.restoreAuthorization(); }
/** * 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); } }