1
0
Fork 0

Add security-field to issus

master
Niki Hansche 2016-09-01 06:56:26 +02:00
parent c9220cb17e
commit 38c443d84f
3 changed files with 109 additions and 1 deletions

View File

@ -149,6 +149,7 @@ public final class Field {
public static final String CREATED_DATE = "created";
public static final String UPDATED_DATE = "updated";
public static final String TRANSITION_TO_STATUS = "to";
public static final String SECURITY = "security";
public static final String DATE_FORMAT = "yyyy-MM-dd";
public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
@ -418,6 +419,8 @@ public final class Field {
result = (T)new Watches(restclient, (JSONObject)r);
else if (type == WorkLog.class)
result = (T)new WorkLog(restclient, (JSONObject)r);
else if (type == Security.class)
result = (T)new Security(restclient, (JSONObject)r);
}
return result;
@ -683,7 +686,7 @@ public final class Field {
SimpleDateFormat df = new SimpleDateFormat(DATETIME_FORMAT);
return df.format(value);
} else if (m.type.equals("issuetype") || m.type.equals("priority") ||
m.type.equals("user") || m.type.equals("resolution")) {
m.type.equals("user") || m.type.equals("resolution") || m.type.equals("securitylevel")) {
JSONObject json = new JSONObject();
if (value == null)

View File

@ -790,6 +790,7 @@ public class Issue extends Resource {
private Integer timeSpent = null;
private Date createdDate = null;
private Date updatedDate = null;
private Security security = null;
/**
* Creates an issue from a JSON payload.
@ -844,6 +845,7 @@ public class Issue extends Resource {
timeSpent = Field.getInteger(fields.get(Field.TIME_SPENT));
createdDate = Field.getDateTime(fields.get(Field.CREATED_DATE));
updatedDate = Field.getDateTime(fields.get(Field.UPDATED_DATE));
security = Field.getResource(Security.class, fields.get(Field.SECURITY), restclient);
}
private static String getRestUri(String key) {
@ -1655,6 +1657,10 @@ public class Issue extends Resource {
return updatedDate;
}
public Security getSecurity() {
return security;
}
public boolean delete(final boolean deleteSubtasks) throws JiraException {
boolean result;
try {
@ -1667,5 +1673,6 @@ public class Issue extends Resource {
}
return result;
}
}

View File

@ -0,0 +1,98 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
/**
* Represents an issue security.
*/
public class Security extends Resource {
private String description = null;
private String name = null;
/**
* Creates a security from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
*/
protected Security(RestClient restclient, JSONObject json) {
super(restclient);
if (json != null)
deserialise(json);
}
private void deserialise(JSONObject json) {
Map map = json;
self = Field.getString(map.get("self"));
id = Field.getString(map.get("id"));
description = Field.getString(map.get("description"));
name = Field.getString(map.get("name"));
}
/**
* Retrieves the given security record.
*
* @param restclient REST client instance
* @param id Internal JIRA ID of the security
*
* @return a security instance
*
* @throws JiraException when the retrieval fails
*/
public static Security get(RestClient restclient, String id)
throws JiraException {
JSON result = null;
try {
result = restclient.get(getBaseUri() + "securitylevel/" + id);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve security " + id, ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
return new Security(restclient, (JSONObject)result);
}
@Override
public String toString() {
return getName();
}
public String getDescription() {
return description;
}
public String getName() {
return name;
}
}