001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.wsclient.unmarshallers;
021
022 import org.sonar.wsclient.services.Review;
023 import org.sonar.wsclient.services.WSUtils;
024
025 /**
026 * @since 2.8
027 */
028 public class ReviewUnmarshaller extends AbstractUnmarshaller<Review> {
029
030 @Override
031 protected Review parse(Object json) {
032 WSUtils utils = WSUtils.getINSTANCE();
033
034 Review review = new Review();
035 review.setId(utils.getLong(json, "id"));
036 review.setCreatedAt(utils.getDateTime(json, "createdAt"));
037 review.setUpdatedAt(utils.getDateTime(json, "updatedAt"));
038 review.setAuthorLogin(utils.getString(json, "author"));
039 review.setAssigneeLogin(utils.getString(json, "assignee"));
040 review.setTitle(utils.getString(json, "title"));
041 review.setStatus(utils.getString(json, "status"));
042 review.setSeverity(utils.getString(json, "severity"));
043 review.setResourceKee(utils.getString(json, "resource"));
044 review.setLine(utils.getInteger(json, "line"));
045 review.setResolution(utils.getString(json, "resolution"));
046 review.setViolationId(utils.getLong(json, "violationId"));
047 review.setType(utils.getString(json, "type"));
048
049 Object comments = utils.getField(json, "comments");
050 if (comments != null) {
051 for (int i = 0; i < utils.getArraySize(comments); i++) {
052 Object comment = utils.getArrayElement(comments, i);
053 review.addComments(utils.getLong(comment, "id"), utils.getDateTime(comment, "updatedAt"), utils.getString(comment, "author"),
054 utils.getString(comment, "text"));
055 }
056 }
057
058 return review;
059 }
060 }