Updated by Francesco:
- new Resource Catalogue Harvester created. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@167720 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
deb7890ea1
commit
09a8f2d2dc
|
@ -40,7 +40,9 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
public static final String RERUN_INPUT_PARAMETER = "reRun";
|
public static final String RERUN_INPUT_PARAMETER = "reRun";
|
||||||
public static final String DRY_RUN_INPUT_PARAMETER = "dryRun";
|
public static final String DRY_RUN_INPUT_PARAMETER = "dryRun";
|
||||||
|
|
||||||
public static final String RESOURCE_CATALOGUE_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue";
|
public static final String RESOURCE_CATALOGUE_CONTEXT = "RESOURCE_CATALOGUE_CONTEXT";
|
||||||
|
|
||||||
|
//public static final String RESOURCE_CATALOGUE_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue";
|
||||||
public static final String TAGME_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
public static final String TAGME_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
||||||
|
|
||||||
protected Date start;
|
protected Date start;
|
||||||
|
@ -63,7 +65,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getConfigParameters() throws IOException {
|
public void getConfigParameters() throws IOException {
|
||||||
try {
|
try {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
InputStream input = AccountingDataHarvesterPlugin.class.getClassLoader()
|
InputStream input = AccountingDataHarvesterPlugin.class.getClassLoader()
|
||||||
|
@ -156,11 +158,17 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
logger.error("Error harvesting Context Users for {}", context, e);
|
logger.error("Error harvesting Context Users for {}", context, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(context.startsWith(RESOURCE_CATALOGUE_CONTEXT)) {
|
//Added by Francesco
|
||||||
|
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
||||||
|
String catalogueContext = (String) properties.get(RESOURCE_CATALOGUE_CONTEXT);
|
||||||
|
logger.debug("Read from properties "+RESOURCE_CATALOGUE_CONTEXT+" value: "+catalogueContext);
|
||||||
|
//end
|
||||||
|
|
||||||
|
if(context.startsWith(catalogueContext)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Collecting info on Resource Catalogue (Dataset, Application, Deliverables, Methods)
|
// Collecting info on Resource Catalogue (Dataset, Application, Deliverables, Methods)
|
||||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end,contexts);
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, catalogueContext, contexts);
|
||||||
List<HarvestedData> harvested = resourceCatalogueHarvester.getData();
|
List<HarvestedData> harvested = resourceCatalogueHarvester.getData();
|
||||||
data.addAll(harvested);
|
data.addAll(harvested);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -169,7 +177,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Collecting info on Data/Method download
|
// Collecting info on Data/Method download
|
||||||
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(start, end,contexts);;
|
DataMethodDownloadHarvester dataMethodDownloadHarvester = new DataMethodDownloadHarvester(start, end,contexts);
|
||||||
List<HarvestedData> harvested = dataMethodDownloadHarvester.getData();
|
List<HarvestedData> harvested = dataMethodDownloadHarvester.getData();
|
||||||
data.addAll(harvested);
|
data.addAll(harvested);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.dataharvest;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.dataharvest.AccountingDataHarvesterPlugin;
|
|
||||||
import org.gcube.vremanagement.executor.plugin.Plugin;
|
import org.gcube.vremanagement.executor.plugin.Plugin;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
package org.gcube.dataharvest.datamodel;
|
package org.gcube.dataharvest.datamodel;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class HarvestedData.
|
||||||
|
*
|
||||||
* @author Eric Perrone (ISTI - CNR)
|
* @author Eric Perrone (ISTI - CNR)
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini
|
||||||
|
* @author Francesco Mangiacrapa (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class HarvestedData implements Serializable {
|
public class HarvestedData implements Serializable {
|
||||||
|
|
||||||
|
@ -14,77 +20,161 @@ public class HarvestedData implements Serializable {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 3699669951917080213L;
|
private static final long serialVersionUID = 3699669951917080213L;
|
||||||
|
|
||||||
public static int ACCESSESS = 1;
|
// public static int ACCESSESS = 1;
|
||||||
public static int USERS = 2;
|
// public static int USERS = 2;
|
||||||
public static int DATA_METHOD_DOWNLOAD = 3;
|
// public static int DATA_METHOD_DOWNLOAD = 3;
|
||||||
public static int NEW_CATALOGUE_METHODS = 4;
|
// public static int NEW_CATALOGUE_METHODS = 4;
|
||||||
public static int NEW_CATALOGUE_DATASETS = 5;
|
// public static int NEW_CATALOGUE_DATASETS = 5;
|
||||||
public static int NEW_CATALOGUE_DELIVERABLES = 6;
|
// public static int NEW_CATALOGUE_DELIVERABLES = 6;
|
||||||
public static int NEW_CATALOGUE_APPLICATIONS = 7;
|
// public static int NEW_CATALOGUE_APPLICATIONS = 7;
|
||||||
public static int SOCIAL_POSTS = 8;
|
// public static int SOCIAL_POSTS = 8;
|
||||||
public static int SOCIAL_REPLIES = 9;
|
// public static int SOCIAL_REPLIES = 9;
|
||||||
public static int SOCIAL_LIKES = 10;
|
// public static int SOCIAL_LIKES = 10;
|
||||||
public static int METHOD_INVOCATIONS = 11;
|
// public static int METHOD_INVOCATIONS = 11;
|
||||||
public static int VISUAL_TOOLS = 12;
|
// public static int VISUAL_TOOLS = 12;
|
||||||
|
|
||||||
private int dataType;
|
private int dataType;
|
||||||
private String context;
|
private String context;
|
||||||
private long measure;
|
private long measure;
|
||||||
private Date day;
|
private Date day;
|
||||||
|
private HarvestedDataKey harvestedDataKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new harvested data.
|
||||||
|
*/
|
||||||
public HarvestedData() {
|
public HarvestedData() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HarvestedData(int dataType, String context, long measure, Date day) {
|
/**
|
||||||
super();
|
* Instantiates a new harvested data.
|
||||||
this.dataType = dataType;
|
*
|
||||||
|
* @param key the key
|
||||||
|
*/
|
||||||
|
private HarvestedData(HarvestedDataKey key){
|
||||||
|
this.harvestedDataKey = key;
|
||||||
|
setDataType(harvestedDataKey.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new harvested data.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param context the context
|
||||||
|
* @param measure the measure
|
||||||
|
* @param day the day
|
||||||
|
*/
|
||||||
|
public HarvestedData(HarvestedDataKey key, String context, long measure, Date day) {
|
||||||
|
this(key);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.measure = measure;
|
this.measure = measure;
|
||||||
this.day = day;
|
this.day = day;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HarvestedData(int dataType, String context, long measure) {
|
/**
|
||||||
this.dataType = dataType;
|
* Instantiates a new harvested data.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param context the context
|
||||||
|
* @param measure the measure
|
||||||
|
*/
|
||||||
|
public HarvestedData(HarvestedDataKey key, String context, long measure) {
|
||||||
|
this(key);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.measure = measure;
|
this.measure = measure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDataType(int dataType) {
|
/**
|
||||||
|
* Sets the data type.
|
||||||
|
*
|
||||||
|
* @param dataType the new data type
|
||||||
|
*/
|
||||||
|
private void setDataType(int dataType) {
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the context.
|
||||||
|
*
|
||||||
|
* @param context the new context
|
||||||
|
*/
|
||||||
public void setContext(String context) {
|
public void setContext(String context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the measure.
|
||||||
|
*
|
||||||
|
* @param measure the new measure
|
||||||
|
*/
|
||||||
public void setMeasure(long measure) {
|
public void setMeasure(long measure) {
|
||||||
this.measure = measure;
|
this.measure = measure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the day.
|
||||||
|
*
|
||||||
|
* @param day the new day
|
||||||
|
*/
|
||||||
public void setDay(Date day) {
|
public void setDay(Date day) {
|
||||||
this.day = day;
|
this.day = day;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the data type.
|
||||||
|
*
|
||||||
|
* @return the data type
|
||||||
|
*/
|
||||||
public int getDataType() {
|
public int getDataType() {
|
||||||
return dataType;
|
return dataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the context.
|
||||||
|
*
|
||||||
|
* @return the context
|
||||||
|
*/
|
||||||
public String getContext() {
|
public String getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the measure.
|
||||||
|
*
|
||||||
|
* @return the measure
|
||||||
|
*/
|
||||||
public long getMeasure() {
|
public long getMeasure() {
|
||||||
return measure;
|
return measure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the day.
|
||||||
|
*
|
||||||
|
* @return the day
|
||||||
|
*/
|
||||||
public Date getDay() {
|
public Date getDay() {
|
||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Harvest [context=" + context + ", dataType=" + dataType + ", measure=" + measure + "]";
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("HarvestedData [dataType=");
|
||||||
|
builder.append(dataType);
|
||||||
|
builder.append(", context=");
|
||||||
|
builder.append(context);
|
||||||
|
builder.append(", measure=");
|
||||||
|
builder.append(measure);
|
||||||
|
builder.append(", day=");
|
||||||
|
builder.append(day);
|
||||||
|
builder.append(", harvestedDataKey=");
|
||||||
|
builder.append(harvestedDataKey);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.dataharvest.datamodel;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* May 22, 2018
|
||||||
|
*/
|
||||||
|
public enum HarvestedDataKey {
|
||||||
|
|
||||||
|
ACCESSESS(1),
|
||||||
|
USERS(2),
|
||||||
|
DATA_METHOD_DOWNLOAD(3),
|
||||||
|
NEW_CATALOGUE_METHODS(4),
|
||||||
|
NEW_CATALOGUE_DATASETS(5),
|
||||||
|
NEW_CATALOGUE_DELIVERABLES(6),
|
||||||
|
NEW_CATALOGUE_APPLICATIONS(7),
|
||||||
|
SOCIAL_POSTS(8),
|
||||||
|
SOCIAL_REPLIES(9),
|
||||||
|
SOCIAL_LIKES(10),
|
||||||
|
METHOD_INVOCATIONS(11),
|
||||||
|
VISUAL_TOOLS(12);
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
HarvestedDataKey(int value){
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the value
|
||||||
|
*/
|
||||||
|
public int getValue() {
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFact
|
||||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.dataharvest.utils.DateUtils;
|
import org.gcube.dataharvest.utils.DateUtils;
|
||||||
import org.gcube.dataharvest.utils.Utils;
|
import org.gcube.dataharvest.utils.Utils;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -72,7 +73,7 @@ public class MethodInvocationHarvester extends BasicHarvester {
|
||||||
JSONObject jsonObject = info.getValue();
|
JSONObject jsonObject = info.getValue();
|
||||||
long numberOfInvocation = jsonObject.getLong(AggregatedUsageRecord.OPERATION_COUNT);
|
long numberOfInvocation = jsonObject.getLong(AggregatedUsageRecord.OPERATION_COUNT);
|
||||||
|
|
||||||
HarvestedData harvestedData = new HarvestedData(HarvestedData.METHOD_INVOCATIONS, context,
|
HarvestedData harvestedData = new HarvestedData(HarvestedDataKey.METHOD_INVOCATIONS, context,
|
||||||
numberOfInvocation);
|
numberOfInvocation);
|
||||||
data.add(harvestedData);
|
data.add(harvestedData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.dataharvest.utils.Utils;
|
import org.gcube.dataharvest.utils.Utils;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -42,15 +43,15 @@ public class SocialInteractionsHarvester extends SocialNetworkingHarvester {
|
||||||
|
|
||||||
getJson();
|
getJson();
|
||||||
|
|
||||||
HarvestedData likesH = new HarvestedData(HarvestedData.SOCIAL_LIKES, context, likes);
|
HarvestedData likesH = new HarvestedData(HarvestedDataKey.SOCIAL_LIKES, context, likes);
|
||||||
logger.debug("{}", likesH);
|
logger.debug("{}", likesH);
|
||||||
data.add(likesH);
|
data.add(likesH);
|
||||||
|
|
||||||
HarvestedData postsH = new HarvestedData(HarvestedData.SOCIAL_POSTS, context, posts);
|
HarvestedData postsH = new HarvestedData(HarvestedDataKey.SOCIAL_POSTS, context, posts);
|
||||||
logger.debug("{}", postsH);
|
logger.debug("{}", postsH);
|
||||||
data.add(postsH);
|
data.add(postsH);
|
||||||
|
|
||||||
HarvestedData socialReplies = new HarvestedData(HarvestedData.SOCIAL_REPLIES, context, replies);
|
HarvestedData socialReplies = new HarvestedData(HarvestedDataKey.SOCIAL_REPLIES, context, replies);
|
||||||
logger.debug("{}", socialReplies);
|
logger.debug("{}", socialReplies);
|
||||||
data.add(socialReplies);
|
data.add(socialReplies);
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ public class SocialInteractionsHarvester extends SocialNetworkingHarvester {
|
||||||
JSONObject item = res.getJSONObject(i);
|
JSONObject item = res.getJSONObject(i);
|
||||||
long time = item.getLong("time");
|
long time = item.getLong("time");
|
||||||
|
|
||||||
if((startDate.getTime() <= time) && (time <= endDate.getTime())) {
|
if(startDate.getTime() <= time && time <= endDate.getTime()) {
|
||||||
posts++;
|
posts++;
|
||||||
replies += item.getInt("comments_no");
|
replies += item.getInt("comments_no");
|
||||||
likes += item.getInt("likes_no");
|
likes += item.getInt("likes_no");
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.dataharvest.utils.Utils;
|
import org.gcube.dataharvest.utils.Utils;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -32,7 +33,7 @@ public class VREUsersHarvester extends SocialNetworkingHarvester {
|
||||||
try {
|
try {
|
||||||
String context = Utils.getCurrentContext();
|
String context = Utils.getCurrentContext();
|
||||||
int measure = get();
|
int measure = get();
|
||||||
HarvestedData harvest = new HarvestedData(HarvestedData.USERS, context, measure);
|
HarvestedData harvest = new HarvestedData(HarvestedDataKey.USERS, context, measure);
|
||||||
logger.debug(harvest.toString());
|
logger.debug(harvest.toString());
|
||||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||||
data.add(harvest);
|
data.add(harvest);
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.gcube.common.homelibrary.jcr.repository.JCRRepository;
|
||||||
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspace;
|
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspace;
|
||||||
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspaceItem;
|
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspaceItem;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.dataharvest.utils.DateUtils;
|
import org.gcube.dataharvest.utils.DateUtils;
|
||||||
import org.gcube.dataharvest.utils.Utils;
|
import org.gcube.dataharvest.utils.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -63,7 +64,7 @@ public class DataMethodDownloadHarvester extends SoBigDataHarvester {
|
||||||
logger.error("Before getStats()");
|
logger.error("Before getStats()");
|
||||||
getStats(item, startDate, endDate);
|
getStats(item, startDate, endDate);
|
||||||
logger.error("After getStats()");
|
logger.error("After getStats()");
|
||||||
HarvestedData harvest = new HarvestedData(HarvestedData.DATA_METHOD_DOWNLOAD, context, count);
|
HarvestedData harvest = new HarvestedData(HarvestedDataKey.DATA_METHOD_DOWNLOAD, context, count);
|
||||||
data.add(harvest);
|
data.add(harvest);
|
||||||
logger.debug(harvest.toString());
|
logger.debug(harvest.toString());
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
package org.gcube.dataharvest.harvester.sobigdata;
|
package org.gcube.dataharvest.harvester.sobigdata;
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
||||||
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
|
||||||
|
import org.gcube.dataharvest.AccountingDataHarvesterPlugin;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.dataharvest.utils.DateUtils;
|
import org.gcube.dataharvest.utils.DateUtils;
|
||||||
import org.gcube.dataharvest.utils.Utils;
|
import org.gcube.dataharvest.utils.Utils;
|
||||||
import org.gcube.portlets.user.urlshortener.UrlEncoderUtil;
|
import org.gcube.portlets.user.urlshortener.UrlEncoderUtil;
|
||||||
|
@ -17,80 +25,147 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class ResourceCatalogueHarvester.
|
||||||
|
*
|
||||||
* @author Eric Perrone (ISTI - CNR)
|
* @author Eric Perrone (ISTI - CNR)
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
* @author Francesco Mangiacrapa(ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ResourceCatalogueHarvester.class);
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final String GROUP_LABEL = "group";
|
||||||
|
|
||||||
private int cityOfCitizensCounter = 0;
|
private static final String AND = " AND ";
|
||||||
private int migrationStudiesCounter = 0;
|
|
||||||
private int societalDebatesCounter = 0;
|
public static int ROWS = 500;
|
||||||
private int wellBeingAndEconomyCounter = 0;
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ResourceCatalogueHarvester.class);
|
||||||
|
|
||||||
protected String solrBaseUrl;
|
protected String solrBaseUrl;
|
||||||
|
|
||||||
public ResourceCatalogueHarvester(Date start, Date end, SortedSet<String> contexts) throws ParseException {
|
private DataCatalogueFactory factory;
|
||||||
|
|
||||||
|
private HashMap<String, String> mapTypeToDBEntry;
|
||||||
|
|
||||||
|
private HashMap<String, String> mapCatalogueGroupToVRE;
|
||||||
|
|
||||||
|
private String catalogueContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new resource catalogue harvester.
|
||||||
|
*
|
||||||
|
* @param start the start
|
||||||
|
* @param end the end
|
||||||
|
* @param catalogueContext the catalogue context
|
||||||
|
* @param contexts the contexts
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public ResourceCatalogueHarvester(Date start, Date end, String catalogueContext, SortedSet<String> contexts) throws Exception {
|
||||||
super(start, end, contexts);
|
super(start, end, contexts);
|
||||||
|
factory = DataCatalogueFactory.getFactory();
|
||||||
|
this.catalogueContext = catalogueContext;
|
||||||
|
|
||||||
|
if(catalogueContext==null || catalogueContext.isEmpty())
|
||||||
|
throw new Exception("The catalogue context is null or empty. Pass a valid scope");
|
||||||
|
|
||||||
|
logger.debug("Catalogue context is: "+catalogueContext);
|
||||||
|
|
||||||
|
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
||||||
|
Set<String> keys = properties.stringPropertyNames();
|
||||||
|
|
||||||
|
mapTypeToDBEntry = new HashMap<String, String>();
|
||||||
|
for (String key : keys) {
|
||||||
|
//System.out.println(key + " : " + properties.getProperty(key));
|
||||||
|
try{
|
||||||
|
HarvestedDataKey valueEnum = HarvestedDataKey.valueOf(key);
|
||||||
|
mapTypeToDBEntry.put(properties.getProperty(key), valueEnum.name());
|
||||||
|
}catch(Exception e){
|
||||||
|
//silent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("Built from properties the mapping 'SystemType' to 'DB entry' : "+mapTypeToDBEntry);
|
||||||
|
|
||||||
|
//GET CATALOGUE'S GROUPS
|
||||||
|
List<String> groups = getGroups(catalogueContext);
|
||||||
|
//NORMALIZING THE GROUP NAME TO MATCH WITH VRE NAME
|
||||||
|
Map<String,String> mapNormalizedGroups = normalizeGroups(groups);
|
||||||
|
logger.debug("Map of Normalized Groups is: "+mapNormalizedGroups);
|
||||||
|
|
||||||
|
//CREATING MAPPING BETWEEN (CATALOGUE GROUP NAME TO VRE NAME)
|
||||||
|
mapCatalogueGroupToVRE = new HashMap<String, String>();
|
||||||
|
Set<String> normalizedGroups = mapNormalizedGroups.keySet();
|
||||||
|
for (String context : contexts) {
|
||||||
|
//logger.trace("Context is: " + context);
|
||||||
|
String loweredVREName =context.substring(context.lastIndexOf("/") + 1, context.length()).toLowerCase();
|
||||||
|
//logger.trace("vreName lowered is: " + loweredVREName);
|
||||||
|
try {
|
||||||
|
if (normalizedGroups.contains(loweredVREName)) {
|
||||||
|
logger.debug("Normalized Groups matching the lowered VRE name: "+loweredVREName);
|
||||||
|
// Creating the map with couple (catalogue group name,
|
||||||
|
// scope)
|
||||||
|
mapCatalogueGroupToVRE.put(mapNormalizedGroups.get(loweredVREName), context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Map of Catalogue Groups To VRE is: "+mapCatalogueGroupToVRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the solr base url.
|
||||||
|
*
|
||||||
|
* @return the solr base url
|
||||||
|
*/
|
||||||
protected String getSolrBaseUrl() {
|
protected String getSolrBaseUrl() {
|
||||||
return "https://ckan-solr-d4s.d4science.org/solr/sobigdata";
|
return "https://ckan-solr-d4s.d4science.org/solr/sobigdata";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.dataharvest.harvester.BasicHarvester#getData()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<HarvestedData> getData() throws Exception {
|
public List<HarvestedData> getData() throws Exception {
|
||||||
|
|
||||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
|
||||||
List<HarvestedData> dataDeliverable = getDataDeliverable();
|
|
||||||
for(HarvestedData harvest : dataDeliverable) {
|
|
||||||
data.add(harvest);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<HarvestedData> dataMethod = getDataMethod();
|
List<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||||
for(HarvestedData harvest : dataMethod) {
|
|
||||||
data.add(harvest);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<HarvestedData> dataDataset = getDataDataset();
|
//FOR EACH SYSTEM_TYPE
|
||||||
for(HarvestedData harvest : dataDataset) {
|
for (String systemType : mapTypeToDBEntry.keySet()) {
|
||||||
data.add(harvest);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<HarvestedData> dataApplication = getDataApplication();
|
List<String> solrParameters = new ArrayList<String>(1);
|
||||||
for(HarvestedData harvest : dataApplication) {
|
solrParameters.add("extras_systemtype:\""+systemType+"\"");
|
||||||
data.add(harvest);
|
//EXECUTING THE QUERY IN THE PERIOD
|
||||||
|
String queryResult = executeQueryFor(solrParameters, startDate, endDate, "groups");
|
||||||
|
HarvestedDataKey insertDBKey = HarvestedDataKey.valueOf(mapTypeToDBEntry.get(systemType));
|
||||||
|
logger.info("Creating statistics for type: "+systemType+ " using db key "+insertDBKey);
|
||||||
|
data.addAll(buildListOfHarvestedData(queryResult, insertDBKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HarvestedData> getDataDeliverable() throws Exception {
|
|
||||||
String json = executeQuery("Deliverable");
|
|
||||||
return buildList(json, HarvestedData.NEW_CATALOGUE_DELIVERABLES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HarvestedData> getDataMethod() throws Exception {
|
/**
|
||||||
String json = executeQuery("Method");
|
* Builds the list of harvested data.
|
||||||
return buildList(json, HarvestedData.NEW_CATALOGUE_METHODS);
|
*
|
||||||
}
|
* @param json the json
|
||||||
|
* @param harvestKey the harvest key
|
||||||
|
* @return the list
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
private List<HarvestedData> buildListOfHarvestedData(String json, HarvestedDataKey harvestKey) throws Exception {
|
||||||
|
|
||||||
public List<HarvestedData> getDataDataset() throws Exception {
|
|
||||||
String json = executeQuery("Dataset");
|
|
||||||
return buildList(json, HarvestedData.NEW_CATALOGUE_DATASETS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HarvestedData> getDataApplication() throws Exception {
|
|
||||||
String json = executeQuery("Application");
|
|
||||||
return buildList(json, HarvestedData.NEW_CATALOGUE_APPLICATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<HarvestedData> buildList(String json, int dataType) throws Exception {
|
|
||||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
|
||||||
JSONObject jsonObject = new JSONObject(json);
|
JSONObject jsonObject = new JSONObject(json);
|
||||||
|
|
||||||
JSONObject responseHeader = jsonObject.getJSONObject("responseHeader");
|
JSONObject responseHeader = jsonObject.getJSONObject("responseHeader");
|
||||||
int status = responseHeader.getInt("status");
|
int status = responseHeader.getInt("status");
|
||||||
if(status != 0) {
|
if(status != 0) {
|
||||||
|
@ -102,10 +177,15 @@ public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
||||||
JSONObject response = jsonObject.getJSONObject("response");
|
JSONObject response = jsonObject.getJSONObject("response");
|
||||||
|
|
||||||
int numFound = response.getInt("numFound");
|
int numFound = response.getInt("numFound");
|
||||||
HarvestedData h = new HarvestedData(dataType,
|
|
||||||
"/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue", numFound);
|
Map<String, Integer> counter = new HashMap<String, Integer>(mapCatalogueGroupToVRE.size()+1);
|
||||||
logger.debug(h.toString());
|
|
||||||
data.add(h);
|
for (String groupName : mapCatalogueGroupToVRE.keySet()) {
|
||||||
|
counter.put(groupName, 0);
|
||||||
|
}
|
||||||
|
//Counter for default context of accounting
|
||||||
|
int catalogueContextCount = 0;
|
||||||
|
logger.debug("For "+harvestKey+" has found "+numFound+" doc/s");
|
||||||
if(numFound > 0) {
|
if(numFound > 0) {
|
||||||
|
|
||||||
JSONArray docs = response.getJSONArray("docs");
|
JSONArray docs = response.getJSONArray("docs");
|
||||||
|
@ -115,70 +195,211 @@ public class ResourceCatalogueHarvester extends SoBigDataHarvester {
|
||||||
JSONArray groups = doc.getJSONArray("groups");
|
JSONArray groups = doc.getJSONArray("groups");
|
||||||
Iterator<Object> git = groups.iterator();
|
Iterator<Object> git = groups.iterator();
|
||||||
while(git.hasNext()) {
|
while(git.hasNext()) {
|
||||||
String groupItem = (String) git.next();
|
String catalogueGroupName = (String) git.next();
|
||||||
counterByGroup(groupItem);
|
logger.debug("GroupName found: "+catalogueGroupName);
|
||||||
|
//counterByGroup(groupItem);
|
||||||
|
Integer currentCount = counter.get(catalogueGroupName);
|
||||||
|
if(currentCount!=null)
|
||||||
|
counter.put(catalogueGroupName, currentCount+1);
|
||||||
|
else{
|
||||||
|
logger.warn("No mapping found for Catalogue-Group Name: "+catalogueGroupName+" from VREs. Accounting it in the catalogue context: "+catalogueContext);
|
||||||
|
//counter.put(catalogueContext, counter.get(catalogueContext)+1);
|
||||||
|
catalogueContextCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break; //Accounting the item only in the first group found
|
||||||
}
|
}
|
||||||
} catch(JSONException x) {
|
} catch(JSONException x) {
|
||||||
logger.debug("Document without groups");
|
logger.debug("Document without groups, accounting it in the catalogue context");
|
||||||
|
catalogueContextCount++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Skipping parsing error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
h = new HarvestedData(dataType, "/d4science.research-infrastructures.eu/SoBigData/CityOfCitizens",
|
List<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||||
cityOfCitizensCounter);
|
logger.trace("The context: "+catalogueContext + " has count: "+catalogueContextCount);
|
||||||
logger.debug(h.toString());
|
data.add(new HarvestedData(harvestKey,catalogueContext, catalogueContextCount));
|
||||||
data.add(h);
|
for (String key : counter.keySet()) {
|
||||||
h = new HarvestedData(dataType, "/Migration Studies", migrationStudiesCounter);
|
logger.trace("The group: "+key + " has count: "+counter.get(key));
|
||||||
logger.debug(h.toString());
|
data.add(new HarvestedData(harvestKey, mapCatalogueGroupToVRE.get(key), counter.get(key)));
|
||||||
data.add(h);
|
}
|
||||||
h = new HarvestedData(dataType, "/d4science.research-infrastructures.eu/SoBigData/SocietalDebates",
|
|
||||||
societalDebatesCounter);
|
|
||||||
logger.debug(h.toString());
|
|
||||||
data.add(h);
|
|
||||||
h = new HarvestedData(dataType, "/d4science.research-infrastructures.eu/SoBigData/WellBeingAndEconomy",
|
|
||||||
wellBeingAndEconomyCounter);
|
|
||||||
logger.debug(h.toString());
|
|
||||||
data.add(h);
|
|
||||||
|
|
||||||
|
logger.info("For "+harvestKey+ " in the period [from "+startDate+" to "+endDate+ "] returning accouting data:");
|
||||||
|
for (HarvestedData harvestedData : data) {
|
||||||
|
logger.info(harvestedData.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String executeQuery(String fqSubString) throws Exception {
|
|
||||||
|
|
||||||
String query = getSolrBaseUrl() + "select?";
|
/**
|
||||||
|
* Gets the groups.
|
||||||
String q = UrlEncoderUtil.encodeQuery("metadata_created:[" + DateUtils.dateToStringWithTZ(startDate) + " TO "
|
*
|
||||||
+ DateUtils.dateToStringWithTZ(endDate) + "]");
|
* @param scope the scope
|
||||||
query += "q=" + q;
|
* @return the groups
|
||||||
String fq = UrlEncoderUtil.encodeQuery("extras_systemtype:\"SoBigData.eu: " + fqSubString + "\"");
|
*/
|
||||||
query += "&fq=" + fq + "&wt=json&indent=true";
|
private List<String> getGroups(String scope){
|
||||||
logger.debug(query);
|
List<String> groups = new ArrayList<String>();
|
||||||
|
String ckanURL = "";
|
||||||
String json = Utils.getJson(query);
|
try {
|
||||||
// logger.debug(json);
|
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||||
|
ckanURL = utils.getCatalogueUrl();
|
||||||
return json;
|
List<CkanGroup> theGroups = utils.getGroups();
|
||||||
}
|
Validate.notNull(theGroups, "The list of Groups is null");
|
||||||
|
for (CkanGroup ckanGroup : theGroups) {
|
||||||
private void counterByGroup(String groupName) {
|
groups.add(ckanGroup.getName());
|
||||||
cityOfCitizensCounter = migrationStudiesCounter = societalDebatesCounter = wellBeingAndEconomyCounter = 0;
|
|
||||||
switch(groupName) {
|
|
||||||
case "city-of-citizens-group":
|
|
||||||
cityOfCitizensCounter++;
|
|
||||||
break;
|
|
||||||
case "migration-studies":
|
|
||||||
migrationStudiesCounter++;
|
|
||||||
break;
|
|
||||||
case "societal-debates-group":
|
|
||||||
societalDebatesCounter++;
|
|
||||||
break;
|
|
||||||
case "well-being-and-economy-group":
|
|
||||||
wellBeingAndEconomyCounter++;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
logger.error("Error occurred on getting CKAN groups for scope: "+scope+" and CKAN URL: "+ckanURL,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Execute query.
|
||||||
|
// *
|
||||||
|
// * @param fqSubString the fq sub string
|
||||||
|
// * @return the string
|
||||||
|
// * @throws Exception the exception
|
||||||
|
// */
|
||||||
|
// //TODO THIS METHOD MUST BE OPTIMIZED USING HttpSolrClient
|
||||||
|
// //We are not considering the rows (the number of documents returned from Solr by default)
|
||||||
|
// private String executeQuery(String fqSubString) throws Exception {
|
||||||
|
//
|
||||||
|
// String query = getSolrBaseUrl().endsWith("/")? getSolrBaseUrl():getSolrBaseUrl()+"/";
|
||||||
|
// query+="select?";
|
||||||
|
//
|
||||||
|
// String q = UrlEncoderUtil.encodeQuery("metadata_created:[" + DateUtils.dateToStringWithTZ(startDate) + " TO "
|
||||||
|
// + DateUtils.dateToStringWithTZ(endDate) + "]");
|
||||||
|
// query += "q=" + q;
|
||||||
|
// String fq = UrlEncoderUtil.encodeQuery("extras_systemtype:\"SoBigData.eu: " + fqSubString + "\"");
|
||||||
|
// query += "&fq=" + fq + "&wt=json&indent=true&rows="+ROWS;
|
||||||
|
// logger.debug("Performing query: "+query);
|
||||||
|
//
|
||||||
|
// String json = Utils.getJson(query);
|
||||||
|
// logger.trace("Response is: "+json);
|
||||||
|
//
|
||||||
|
// return json;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute query.
|
||||||
|
*
|
||||||
|
* @param solrParameters the solr parameters
|
||||||
|
* @param startDate the start date
|
||||||
|
* @param endDate the end date
|
||||||
|
* @param flValue the fl value
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
//TODO THIS METHOD MUST BE OPTIMIZED USING HttpSolrClient
|
||||||
|
//We are not considering the rows (the number of documents returned from Solr by default)
|
||||||
|
public String executeQueryFor(List<String> solrParameters, Date startDate, Date endDate, String flValue) throws Exception {
|
||||||
|
|
||||||
|
String query = getSolrBaseUrl().endsWith("/")? getSolrBaseUrl():getSolrBaseUrl()+"/";
|
||||||
|
query+="select?";
|
||||||
|
|
||||||
|
String q="";
|
||||||
|
//ADDING START AND END DATE IF ARE VALIDS
|
||||||
|
if(startDate!=null && endDate!=null){
|
||||||
|
q+= "metadata_created:[" + DateUtils.dateToStringWithTZ(startDate) + " TO " + DateUtils.dateToStringWithTZ(endDate) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
//ADDING PARAMETERS
|
||||||
|
if(solrParameters!=null && solrParameters.size()>0){
|
||||||
|
q+= q.isEmpty()?"":AND;
|
||||||
|
|
||||||
|
for (int i = 0; i < solrParameters.size()-1; i++) {
|
||||||
|
q+= solrParameters.get(i)+AND;
|
||||||
|
}
|
||||||
|
|
||||||
|
q+= solrParameters.get(solrParameters.size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
query += "q=" + UrlEncoderUtil.encodeQuery(q) + "&wt=json&indent=true&rows="+ROWS;
|
||||||
|
query += flValue!=null && !flValue.isEmpty()?"&fl="+UrlEncoderUtil.encodeQuery(flValue):"";
|
||||||
|
logger.debug("\nPerforming query: "+query);
|
||||||
|
String jsonResult = Utils.getJson(query);
|
||||||
|
logger.trace("Response is: "+jsonResult);
|
||||||
|
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the catalogue context.
|
||||||
|
*
|
||||||
|
* @return the catalogueContext
|
||||||
|
*/
|
||||||
|
public String getCatalogueContext() {
|
||||||
|
|
||||||
|
return catalogueContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the catalogue context.
|
||||||
|
*
|
||||||
|
* @param catalogueContext the catalogueContext to set
|
||||||
|
*/
|
||||||
|
public void setCatalogueContext(String catalogueContext) {
|
||||||
|
|
||||||
|
this.catalogueContext = catalogueContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize groups.
|
||||||
|
*
|
||||||
|
* @param groups the groups
|
||||||
|
* @return the map with couple (normalized group name, group name)
|
||||||
|
*/
|
||||||
|
private Map<String,String> normalizeGroups(List<String> groups) {
|
||||||
|
Map<String,String> listNGroups = new HashMap<String,String>(groups.size());
|
||||||
|
for (String group : groups) {
|
||||||
|
String normalizedGroup = group;
|
||||||
|
if(normalizedGroup.endsWith(GROUP_LABEL)){
|
||||||
|
normalizedGroup = normalizedGroup.substring(0, normalizedGroup.length()-GROUP_LABEL.length());
|
||||||
|
}
|
||||||
|
normalizedGroup = normalizedGroup.replaceAll("-","");
|
||||||
|
listNGroups.put(normalizedGroup.toLowerCase(), group);
|
||||||
|
}
|
||||||
|
return listNGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Gets the data francesco.
|
||||||
|
// *
|
||||||
|
// * @return the data francesco
|
||||||
|
// * @throws Exception the exception
|
||||||
|
// */
|
||||||
|
// public List<HarvestedData> getDataFrancesco() throws Exception {
|
||||||
|
//
|
||||||
|
// List<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||||
|
//
|
||||||
|
// //FOR EACH SYSTEM_TYPE
|
||||||
|
// for (String systemType : mapTypeToDBEntry.keySet()) {
|
||||||
|
//
|
||||||
|
// List<String> solrParameters = new ArrayList<String>(1);
|
||||||
|
// solrParameters.add("extras_systemtype:\""+systemType+"\"");
|
||||||
|
// //EXECUTING THE QUERY IN THE PERIOD
|
||||||
|
// String queryResult = executeQueryFor(solrParameters, startDate, endDate, "groups");
|
||||||
|
// HarvestedDataKey insertDBKey = HarvestedDataKey.valueOf(mapTypeToDBEntry.get(systemType));
|
||||||
|
// logger.info("Creating statistics for type: "+systemType+ " using db key "+insertDBKey);
|
||||||
|
// data.addAll(buildListOfHarvestedData(queryResult, insertDBKey));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return data;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
|
import org.gcube.dataharvest.datamodel.HarvestedDataKey;
|
||||||
import org.gcube.dataharvest.harvester.BasicHarvester;
|
import org.gcube.dataharvest.harvester.BasicHarvester;
|
||||||
import org.gcube.dataharvest.utils.DateUtils;
|
import org.gcube.dataharvest.utils.DateUtils;
|
||||||
import org.gcube.dataharvest.utils.Utils;
|
import org.gcube.dataharvest.utils.Utils;
|
||||||
|
@ -71,7 +72,7 @@ public class TagMeMethodInvocationHarvester extends BasicHarvester {
|
||||||
JSONObject jsonObject = info.getValue();
|
JSONObject jsonObject = info.getValue();
|
||||||
long numberOfInvocation = jsonObject.getLong(AggregatedUsageRecord.OPERATION_COUNT);
|
long numberOfInvocation = jsonObject.getLong(AggregatedUsageRecord.OPERATION_COUNT);
|
||||||
|
|
||||||
HarvestedData harvestedData = new HarvestedData(HarvestedData.METHOD_INVOCATIONS, context,
|
HarvestedData harvestedData = new HarvestedData(HarvestedDataKey.METHOD_INVOCATIONS, context,
|
||||||
numberOfInvocation);
|
numberOfInvocation);
|
||||||
data.add(harvestedData);
|
data.add(harvestedData);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.dataharvest.utils;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -63,8 +62,9 @@ public class ContextAuthorization {
|
||||||
try {
|
try {
|
||||||
String context = map.get(scope).toString();
|
String context = map.get(scope).toString();
|
||||||
logger.info("Going to generate Token for Context {}", context);
|
logger.info("Going to generate Token for Context {}", context);
|
||||||
UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME),
|
// UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME),
|
||||||
new ArrayList<>());
|
// new ArrayList<>());
|
||||||
|
UserInfo userInfo = null;
|
||||||
String userToken = authorizationService().generateUserToken(userInfo, context);
|
String userToken = authorizationService().generateUserToken(userInfo, context);
|
||||||
SecurityTokenProvider.instance.set(userToken);
|
SecurityTokenProvider.instance.set(userToken);
|
||||||
String generatedToken = authorizationService()
|
String generatedToken = authorizationService()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPluginTest.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPluginTest.class);
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void testMethodInvocation() {
|
public void testMethodInvocation() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void testTagMeMethodInvocation() {
|
public void testTagMeMethodInvocation() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -101,31 +102,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testResourceCatalogueHarvester() {
|
|
||||||
try {
|
|
||||||
|
|
||||||
org.gcube.dataharvest.utils.Utils.setContext(RESOURCE_CATALOGUE);
|
//@Test
|
||||||
|
|
||||||
MeasureType measureType = MeasureType.MONTHLY;
|
|
||||||
|
|
||||||
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
||||||
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
|
||||||
|
|
||||||
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
|
||||||
SortedSet<String> contexts = new TreeSet<>(map.keySet());
|
|
||||||
|
|
||||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, contexts);
|
|
||||||
List<HarvestedData> harvestedData = resourceCatalogueHarvester.getData();
|
|
||||||
|
|
||||||
logger.debug("{}", harvestedData);
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
|
||||||
logger.error("", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFilteringGenericResource() {
|
public void testFilteringGenericResource() {
|
||||||
try {
|
try {
|
||||||
org.gcube.dataharvest.utils.Utils.setContext(RESOURCE_CATALOGUE);
|
org.gcube.dataharvest.utils.Utils.setContext(RESOURCE_CATALOGUE);
|
||||||
|
@ -139,7 +117,16 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
||||||
SortedSet<String> contexts = new TreeSet<>(map.keySet());
|
SortedSet<String> contexts = new TreeSet<>(map.keySet());
|
||||||
|
|
||||||
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, contexts);
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null);
|
||||||
|
accountingDataHarvesterPlugin.getConfigParameters();
|
||||||
|
|
||||||
|
//Added by Francesco
|
||||||
|
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
||||||
|
String catalogueContext = (String) properties.get(AccountingDataHarvesterPlugin.RESOURCE_CATALOGUE_CONTEXT);
|
||||||
|
logger.debug("Read from properties "+AccountingDataHarvesterPlugin.RESOURCE_CATALOGUE_CONTEXT+" value: "+catalogueContext);
|
||||||
|
//end
|
||||||
|
|
||||||
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, catalogueContext, contexts);
|
||||||
SortedSet<String> excludedContexts = resourceCatalogueHarvester.getExcludedContexts();
|
SortedSet<String> excludedContexts = resourceCatalogueHarvester.getExcludedContexts();
|
||||||
logger.info("Excluded contexts {}", excludedContexts);
|
logger.info("Excluded contexts {}", excludedContexts);
|
||||||
SortedSet<String> validContexts = resourceCatalogueHarvester.getFilteredContexts();
|
SortedSet<String> validContexts = resourceCatalogueHarvester.getFilteredContexts();
|
||||||
|
@ -151,4 +138,75 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResourceCatalogueHarvester() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
||||||
|
// //Enumeration<String> enums = (Enumeration<String>) properties.propertyNames();
|
||||||
|
// //System.out.println("enums: " +enums.hasMoreElements());
|
||||||
|
// Set<String> keys = properties.stringPropertyNames();
|
||||||
|
//
|
||||||
|
// Map<String, String> typeToDB = new HashMap<String, String>();
|
||||||
|
// for (String key : keys) {
|
||||||
|
// System.out.println(key + " : " + properties.getProperty(key));
|
||||||
|
//
|
||||||
|
// try{
|
||||||
|
// HarvestedDataKey valueEnum = HarvestedDataKey.valueOf(key);
|
||||||
|
// typeToDB.put(properties.getProperty(key), valueEnum.name());
|
||||||
|
// }catch(Exception e){
|
||||||
|
// //silent
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// System.out.println(typeToDB);
|
||||||
|
|
||||||
|
org.gcube.dataharvest.utils.Utils.setContext(RESOURCE_CATALOGUE);
|
||||||
|
|
||||||
|
MeasureType measureType = MeasureType.MONTHLY;
|
||||||
|
|
||||||
|
// Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
||||||
|
// Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
||||||
|
|
||||||
|
//Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
||||||
|
Date start = DateUtils.getStartCalendar(2016, 12, 01).getTime();
|
||||||
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 18);
|
||||||
|
|
||||||
|
LinkedHashMap<String,ScopeBean> map = ContextManager.readContexts();
|
||||||
|
SortedSet<String> contexts = new TreeSet<>(map.keySet());
|
||||||
|
|
||||||
|
for (String context : contexts) {
|
||||||
|
System.out.println("context: "+context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null);
|
||||||
|
accountingDataHarvesterPlugin.getConfigParameters();
|
||||||
|
|
||||||
|
//Added by Francesco
|
||||||
|
Properties properties = AccountingDataHarvesterPlugin.getProperties().get();
|
||||||
|
String catalogueContext = (String) properties.get(AccountingDataHarvesterPlugin.RESOURCE_CATALOGUE_CONTEXT);
|
||||||
|
logger.debug("Read from properties "+AccountingDataHarvesterPlugin.RESOURCE_CATALOGUE_CONTEXT+" value: "+catalogueContext);
|
||||||
|
//end
|
||||||
|
|
||||||
|
contexts = new TreeSet<String>();
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue");
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/TagMe");
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/WellBeingAndEconomy");
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/CityOfCitizens");
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/SocietalDebates");
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/SportsDataScience");
|
||||||
|
contexts.add("/d4science.research-infrastructures.eu/SoBigData/SMAPH");
|
||||||
|
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end, catalogueContext, contexts);
|
||||||
|
List<HarvestedData> data = resourceCatalogueHarvester.getData();
|
||||||
|
|
||||||
|
for (HarvestedData harvestedData : data) {
|
||||||
|
System.out.println(harvestedData.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(Exception e) {
|
||||||
|
logger.error("", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue