Project

General

Profile

1
//package eu.dnetlib.uoaadmintools.handlers.utils;
2
//
3
//import com.google.gson.Gson;
4
//import org.apache.log4j.Logger;
5
//
6
//import java.io.BufferedReader;
7
//import java.io.InputStreamReader;
8
//import java.io.StringReader;
9
//import java.net.HttpURLConnection;
10
//import java.net.URL;
11
//import java.util.ArrayList;
12
//import java.util.List;
13
//
14
///**
15
// * Created by argirok on 27/2/2018.
16
// */
17
//public class CommunityInfo {
18
//
19
//    List<String> managers = new ArrayList<String>();
20
//    private final Logger log = Logger.getLogger(this.getClass());
21
//
22
//    public List<String> getManagers() {
23
//        return managers;
24
//    }
25
//
26
//    public void setManagers(List<String> managers) {
27
//        this.managers = managers;
28
//    }
29
//
30
//    private CommunityInfo getCommunityInfo(String communityAPI, String community) {
31
//        String url = communityAPI + community;
32
//        URL obj = null;
33
//        String responseStr = null;
34
//        log.debug("Community info url is " + url);
35
//
36
//        try {
37
//            obj = new URL(url);
38
//            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
39
//            log.debug("User info response code is: " + con.getResponseCode());
40
//            if (con.getResponseCode() != 200) {
41
//                return null;
42
//            }
43
//            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
44
//            StringBuffer response = new StringBuffer();
45
//            String inputLine;
46
//            while ((inputLine = in.readLine()) != null) {
47
//                response.append(inputLine).append("\n");
48
//            }
49
//            in.close();
50
//            responseStr = response.toString();
51
//        } catch (Exception e) {
52
//            log.error("An error occured while trying to fetch user info ", e);
53
//            return null;
54
//        }
55
//        return json2CommunityInfo(community);
56
//    }
57
//    private  CommunityInfo json2CommunityInfo(String json){
58
//
59
//        log.debug("Try to create CommunityInfo class from json: "+json);
60
//        if (json == null){
61
//            return null;
62
//        }
63
//
64
//        BufferedReader br = new BufferedReader(new StringReader(json));
65
//        //convert the json string back to object
66
//        Gson gson = new Gson();
67
//        CommunityInfo communityInfo = null;
68
//        try {
69
//            communityInfo = gson.fromJson(br, CommunityInfo.class);
70
//        }catch(Exception e){
71
//            log.debug("Error in parsing json response. Given json is : "+json, e);
72
//            return null;
73
//        }
74
//
75
//        log.debug("Original response.........: "+communityInfo.toString());
76
//
77
//
78
//
79
//        return communityInfo;
80
//    }
81
//}
(2-2/3)