9 package cz.vutbr.fit.knot.annotations.modules.suggestionManager;
 
   12 import java.util.ArrayList;
 
   13 import java.util.Iterator;
 
   14 import java.util.logging.Level;
 
   15 import java.util.logging.Logger;
 
   16 import org.json.simple.JSONArray;
 
   17 import org.json.simple.JSONObject;
 
   18 import org.json.simple.JSONValue;
 
   27   public static ArrayList<SecApiReqTypeDef> 
translate(String typesData) {
 
   28     ArrayList<SecApiReqTypeDef> result = 
new ArrayList<SecApiReqTypeDef>();
 
   29     if (typesData == null || typesData.isEmpty()) {
 
   32     JSONObject jsonData = (JSONObject)JSONValue.parse(typesData);
 
   33     if (jsonData == null) {
 
   35         String msg = 
"Unable to parse received JSON string with types and attributes.";
 
   36         Logger.getLogger(SECTypesTranslator.class.getName()).log(Level.SEVERE, msg);
 
   44       JSONArray jsonTypes = (JSONArray)jsonData.get(
"data");
 
   45       if (jsonTypes == null || jsonTypes.isEmpty()) {
 
   47           String msg = 
"Unable to get types and attributes.";
 
   48           Logger.getLogger(SECTypesTranslator.class.getName()).log(Level.SEVERE, msg);
 
   51       int typesLength = jsonTypes.size();
 
   52       for (
int i = 0; i < typesLength; i++) {
 
   53         JSONObject typesItem = (JSONObject)jsonTypes.get(i);
 
   54         String name = (String)typesItem.get(
"type");
 
   55         if (name == null || name.isEmpty()) {
 
   61         JSONArray attributes = (JSONArray)typesItem.get(
"attributes");
 
   63         int attLength = attributes.size();
 
   64         for (
int j = 0; j < attLength; j++) {
 
   65           String attItem = (String) attributes.get(j);
 
   66           if (attItem == null || attItem.isEmpty()) {
 
   69           satd.addAvailableAttribute(attItem);
 
   74           satd.addAvailableAttribute(
"identifier");
 
   79           satd.addAvailableAttribute(
"disambiguation");
 
   84           satd.addAvailableAttribute(
"confidence");
 
   87         JSONObject priorities = (JSONObject)typesItem.get(
"priorities");
 
   88         if (priorities != null) {
 
   89           Iterator<String> attIt = satd.getAvailableAttributes().iterator();
 
   90           while (attIt.hasNext()) {
 
   91             String att = attIt.next();
 
   93               Long priority = (Long) priorities.get(att);
 
   94               if (priority != null) {
 
   95                 satd.setPriority(att, priority.intValue());
 
   97             } 
catch (Exception e) {
 
   99                 String msg = 
"Unable to load priority of attribute.";
 
  100                 Logger.getLogger(SECTypesTranslator.class.getName()).log(Level.SEVERE, msg, e);
 
  109     } 
catch (Exception e) {
 
  111         String msg = 
"Unable to parse received JSON string with types and attributes.";
 
  112         Logger.getLogger(SECTypesTranslator.class.getName()).log(Level.SEVERE, msg, e);
 
  128     String exceptionData = null;
 
  130       exceptionData = (String) jsonData.get(
"exception");
 
  131     } 
catch (Exception e) {  
 
  133     if (exceptionData != null && !exceptionData.isEmpty()) {
 
  135         String msg = 
"SEC API returned exception: " + exceptionData;
 
  136         Logger.getLogger(SECTypesTranslator.class.getName()).log(Level.SEVERE, msg);
 
static final Boolean ADD_IDENTIFIER
static boolean checkException(JSONObject jsonData)
static final Boolean ADD_DISAMBIGUATION
static ArrayList< SecApiReqTypeDef > translate(String typesData)
ArrayList< String > getAvailableAttributes()
Class for creating of requested type definition for SEC API. 
static final int LOG_LEVEL
static final int LOG_LEVEL_SERVER_ERRORS
static final Boolean ADD_CONFIDENCE
Translates JSON with types from SEC API to requested type definitions.