private SubmitType getSubmitType(ChangeData cd) { try { SubmitTypeRecord str = cd.submitTypeRecord(); return str.isOk() ? str.type : null; } catch (OrmException e) { logError("Failed to get submit type for " + cd.getId(), e); return null; } }
private SubmitTypeRecord typeError(String err, Exception e) { if (logErrors) { if (e == null) { log.error(err); } else { log.error(err, e); } return defaultTypeError(); } else { return SubmitTypeRecord.error(err); } }
public static SubmitTypeRecord defaultTypeError() { return SubmitTypeRecord.error(DEFAULT_MSG); }
/** * Evaluate the submit type rules to get the submit type. * * @return record from the evaluated rules. */ public SubmitTypeRecord getSubmitType() { try { initPatchSet(); } catch (OrmException e) { return typeError("Error looking up patch set " + control.getChange().currentPatchSetId()); } try { if (control.getChange().getStatus() == Change.Status.DRAFT && !control.isDraftVisible(cd.db(), cd)) { return SubmitTypeRecord.error("Patch set " + patchSet.getId() + " not found"); } if (patchSet.isDraft() && !control.isDraftVisible(cd.db(), cd)) { return SubmitTypeRecord.error("Patch set " + patchSet.getId() + " not found"); } } catch (OrmException err) { String msg = "Cannot read patch set " + patchSet.getId(); log.error(msg, err); return SubmitTypeRecord.error(msg); } List<Term> results; try { results = evaluateImpl( "locate_submit_type", "get_submit_type", "locate_submit_type_filter", "filter_submit_type_results", // Do not include current user in submit type evaluation. This is used // for mergeability checks, which are stored persistently and so must // have a consistent view of the submit type. null); } catch (RuleEvalException e) { return typeError(e.getMessage(), e); } if (results.isEmpty()) { // Should never occur for a well written rule return typeError( "Submit rule '" + getSubmitRuleName() + "' for change " + cd.getId() + " of " + getProjectName() + " has no solution."); } Term typeTerm = results.get(0); if (!(typeTerm instanceof SymbolTerm)) { return typeError( "Submit rule '" + getSubmitRuleName() + "' for change " + cd.getId() + " of " + getProjectName() + " did not return a symbol."); } String typeName = ((SymbolTerm) typeTerm).name(); try { return SubmitTypeRecord.OK(SubmitType.valueOf(typeName.toUpperCase())); } catch (IllegalArgumentException e) { return typeError( "Submit type rule " + getSubmitRule() + " for change " + cd.getId() + " of " + getProjectName() + " output invalid result: " + typeName); } }