61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
package org.gcube.dataharvest.harvester;
|
|
|
|
import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
|
import org.gcube.dataharvest.utils.Utils;
|
|
import org.json.JSONObject;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Eric Perrone (ISTI - CNR)
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class VREUsersHarvester extends SocialNetworkingHarvester {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(VREUsersHarvester.class);
|
|
|
|
|
|
public static final String PATH = "/2/users/get-all-usernames?gcube-token=";
|
|
|
|
public VREUsersHarvester(Date start, Date end) throws ParseException {
|
|
super(start, end);
|
|
}
|
|
|
|
@Override
|
|
public List<HarvestedData> getData() throws Exception {
|
|
try {
|
|
String context = Utils.getCurrentContext();
|
|
int measure = get();
|
|
HarvestedData harvest = new HarvestedData(HarvestedDataKey.USERS, context, measure);
|
|
logger.debug(harvest.toString());
|
|
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
|
data.add(harvest);
|
|
return data;
|
|
} catch(Exception e) {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
private int get() throws Exception {
|
|
JSONObject jsonObject = getJSONObject(PATH);
|
|
|
|
int userNumber = 0;
|
|
|
|
Boolean success = (Boolean) jsonObject.get("success");
|
|
if(success == false) {
|
|
throw new IOException("Erro while getting VRE Users");
|
|
}
|
|
|
|
userNumber = jsonObject.getJSONArray("result").length();
|
|
return userNumber;
|
|
}
|
|
|
|
}
|