SCMRevision toSCMRevision(Map map) { try { if (map == null || map.get("revision") == null) { throw new RuntimeException("SCM revision cannot be empty"); } Map revisionMap = null; try { revisionMap = (Map) map.get("revision"); } catch (Exception e) { throw new RuntimeException("SCM revision should be of type map"); } return getScmRevisionFromMap(revisionMap); } catch (Exception e) { throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage())); } }
List<SCMRevision> toSCMRevisions(Map map) { try { List<SCMRevision> scmRevisions = new ArrayList<>(); if (map == null || map.get("revisions") == null) { return scmRevisions; } List revisionMaps = null; try { revisionMaps = (List) map.get("revisions"); } catch (Exception e) { throw new RuntimeException("'revisions' should be of type list of map"); } if (revisionMaps != null && !revisionMaps.isEmpty()) { for (Object revision : revisionMaps) { if (!(revision instanceof Map)) { throw new RuntimeException("SCM revision should be of type map"); } } for (Object revisionObj : revisionMaps) { Map revisionMap = (Map) revisionObj; SCMRevision scmRevision = getScmRevisionFromMap(revisionMap); scmRevisions.add(scmRevision); } } return scmRevisions; } catch (Exception e) { throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage())); } }
private String errorMessageForEachRevision(String message) { try { Map revisionMap = (Map) new GsonBuilder().create().fromJson(message, Object.class); messageHandler.getScmRevisionFromMap(revisionMap); fail("should have thrown exception"); } catch (Exception e) { return e.getMessage(); } return null; }