Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.belladati.sdk.impl;
  
  import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 
 
 class BellaDatiServiceImpl implements BellaDatiService {

The serialVersionUID
 
 	private static final long serialVersionUID = 9054278401541000710L;
 
 	public static final String DATE_TIME_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
 
 
 	private final transient PaginatedIdList<DashboardInfodashboardList = new DashboardList();
 
 	private final transient PaginatedIdList<ReportInforeportList = new ReportList();
 
 	private final transient PaginatedIdList<DataSetInfodataSetList = new DataSetList();
 
 	private final transient Map<StringPaginatedList<Comment>> commentLists = Collections
 
 
 	private final transient Map<StringCachedListImpl<DataSource>> dataSourceList = new HashMap<StringCachedListImpl<DataSource>>();
 
 
 	BellaDatiServiceImpl(BellaDatiClient clientTokenHolder tokenHolder) {
 		this. = client;
 		this. = tokenHolder;
 	}
 
 		return ;
 	}
 
 	public Dashboard loadDashboard(String id) {
 		return new DashboardImpl(thisloadJson("api/dashboards/" + id));
 	}
 
 	public Object loadDashboardThumbnail(String idthrows IOException {
 		return loadImage("api/dashboards/" + id + "/thumbnail");
	}
		return ;
	}
	public Report loadReport(String id) {
		return new ReportImpl(thisloadJson("api/reports/" + id));
	}
	public Object loadReportThumbnail(String reportIdthrows IOException {
		return loadImage("api/reports/" + reportId + "/thumbnail");
	}

Convenience method for other parts of the implementation to easily load data through the API.

Parameters:
uri URI to contact
Returns:
the resulting JSON response
		return .getJson(uri);
	}

Loads an image from the given URI.

Parameters:
relativeUrl the URI to load from
Returns:
the image from the server
Throws:
java.io.IOException if the image cannot be loaded
	private Object loadImage(String relativeUrlthrows IOException {
		try {
			Bitmap image = BitmapFactory.decodeStream(bais);
			if (image == null) {
				throw new IOException("Could not load image");
			}
			return image;
finally {
			bais.close();
		}
	}
		PaginatedList<Commentexisting = .get(reportId);
		if (existing != null) {
			return existing;
else {
			synchronized () {
				existing = .get(reportId);
				if (existing != null) {
					return existing;
else {
						"api/reports/" + reportId + "/comments""comments") {
						protected Comment parse(BellaDatiServiceImpl serviceJsonNode node) {
							return new CommentImpl(servicenode);
						}
					};
					.put(reportIdnewList);
					return newList;
				}
			}
		}
	}
	public void postComment(String reportIdString text) {
		.post("api/reports/" + reportId + "/comments",
			Collections.singletonList(new BasicNameValuePair("text"text)));
	}
	public Object loadViewContent(String viewIdViewType viewTypeFilter<?>... filters) {
		return loadViewContent(viewIdviewType, Arrays.asList(filters));
	}
	public Object loadViewContent(String viewIdViewType viewTypeCollection<Filter<?>> filters) {
		return createViewLoader(viewIdviewType).addFilters(filters).loadContent();
	}
	public ViewLoader createViewLoader(String viewIdViewType viewType) {
		return new ViewLoaderImpl(thisviewIdviewType);
	}
		if (list == null) {
			// we don't have this data set's sources in our cache yet
			list = new CachedListImpl<DataSource>(this"api/dataSets/" + id + "/dataSources""dataSources") {
				protected DataSource parse(BellaDatiServiceImpl serviceJsonNode nodethrows ParseException {
					return new DataSourceImpl(servicenode);
				}
			};
			.put(idlist);
		}
		return list;
	}
		if (list == null) {
			// we don't have this data set's sources in our cache yet
			list = new CachedListImpl<DataSourceImport>(this"api/dataSets/dataSources/" + id + "/executions""executions") {
				protected DataSourceImport parse(BellaDatiServiceImpl serviceJsonNode nodethrows ParseException {
					try {
						return new DataSourceImportImpl(node);
						throw new ParseException(nodee);
					}
				}
			};
		}
		return list;
	}
		return new DataSourcePendingImportImpl(thisiddate);
	}

Appends a filter parameter from the given filters to the URI builder. Won't do anything if the filter collection is empty.

Parameters:
builder the builder to append to
filters filters to append
Returns:
the same builder, for chaining
	URIBuilder appendFilter(URIBuilder builderCollection<Filter<?>> filters) {
		if (filters.size() > 0) {
			ObjectNode filterNode = new ObjectMapper().createObjectNode();
			for (Filter<?> filter : filters) {
				filterNode.setAll(filter.toJson());
			}
			ObjectNode drilldownNode = new ObjectMapper().createObjectNode();
			drilldownNode.put("drilldown"filterNode);
			builder.addParameter("filter"drilldownNode.toString());
		}
		return builder;
	}

Appends a date/time definition parameter to the URI builder. Won't do anything if both intervals are null.

Parameters:
builder the builder to append to
dateInterval date interval to append, or null
timeInterval time interval to append, or null
Returns:
the same builder, for chaining
	URIBuilder appendDateTime(URIBuilder builderInterval<DateUnitdateIntervalInterval<TimeUnittimeInterval) {
		if (dateInterval != null || timeInterval != null) {
			ObjectNode dateTimeNode = new ObjectMapper().createObjectNode();
			if (dateInterval != null) {
				dateTimeNode.setAll(dateInterval.toJson());
			}
			if (timeInterval != null) {
				dateTimeNode.setAll(timeInterval.toJson());
			}
			builder.addParameter("dateTimeDefinition"dateTimeNode.toString());
		}
		return builder;
	}

Appends a locale language parameter to the URI builder. Won't do anything if the locale is null.

Parameters:
builder the builder to append to
locale the locale to append
Returns:
the same builder, for chaining
	URIBuilder appendLocale(URIBuilder builderLocale locale) {
		if (locale != null) {
			builder.addParameter("lang"locale.getLanguage());
		}
		return builder;
	}
	public synchronized CachedList<AttributeValuegetAttributeValues(String reportIdString attributeCode) {
			// we don't have any values for this report yet, insert new map
		}
		CachedListImpl<AttributeValuevalues = attributeValues.get(attributeCode);
		if (values == null) {
			// we don't have this attribute in our cache yet
			values = new CachedListImpl<AttributeValue>(this"api/reports/" + reportId
"/filter/drilldownAttributeValues?code=" + attributeCode"values") {
				protected AttributeValue parse(BellaDatiServiceImpl serviceJsonNode nodethrows ParseException {
					try {
						return new AttributeValueImpl(node);
						throw new ParseException(nodee);
					}
				}
			};
			attributeValues.put(attributeCodevalues);
		}
		return values;
	}
	public User loadUser(String userId) {
		return new UserImpl(loadJson("api/users/" + userId));
	}
	public Object loadUserImage(String userIdthrows IOException {
		return loadImage("api/users/" + userId + "/image");
	}
	public String toString() {
		return "BellaDati Service(server: " + .getBaseUrl() + ", key: " + .getConsumerKey() + ", token: "
.getToken() + ")";
	}
		return ;
	}
	public DataSet loadDataSet(String idthrows NotFoundException {
		return new DataSetImpl(thisloadJson("api/dataSets/" + id));
	}
	public void uploadData(String idDataTable data) {
		List<DataRowrows = data.getRows();
		if (rows.size() == 0) {
			// if we don't have data, do nothing
			return;
		}
		try {
			.postUpload("api/import/" + iddata.toJson().toString());
			if (e.getResponseCode() == 400) {
				Pattern codePattern = Pattern.compile(".*?'(.*?)'.*");
				Matcher codeMatcher = codePattern.matcher(e.getResponseContent());
				if (codeMatcher.matches()) {
					throw new UnknownServerColumnException(idcodeMatcher.group(1));
				}
			}
		}
	}

Deserialization. Sets up the element lists and maps as empty objects.
		try {
			Field dashboardList = getClass().getDeclaredField("dashboardList");
			dashboardList.setAccessible(true);
			dashboardList.set(thisnew DashboardList());
			Field reportList = getClass().getDeclaredField("reportList");
			reportList.setAccessible(true);
			reportList.set(thisnew ReportList());
			Field dataSetList = getClass().getDeclaredField("dataSetList");
			dataSetList.setAccessible(true);
			dataSetList.set(thisnew DataSetList());
			Field commentLists = getClass().getDeclaredField("commentLists");
			commentLists.setAccessible(true);
			commentLists.set(this, Collections.synchronizedMap(new HashMap<StringPaginatedList<Comment>>()));
			Field reportAttributeValues = getClass().getDeclaredField("reportAttributeValues");
			reportAttributeValues.setAccessible(true);
			reportAttributeValues.set(thisnew HashMap<StringMap<StringCachedListImpl<AttributeValue>>>());
			Field dataSourceList = getClass().getDeclaredField("dataSourceList");
			dataSourceList.setAccessible(true);
			dataSourceList.set(thisnew HashMap<StringCachedListImpl<DataSource>>());
			Field dataSourceImportList = getClass().getDeclaredField("dataSourceImportList");
			dataSourceImportList.setAccessible(true);
			dataSourceImportList.set(thisnew HashMap<StringCachedListImpl<DataSourceImport>>());
catch (NoSuchFieldException e) {
			throw new InternalConfigurationException("Failed to set service fields"e);
catch (IllegalAccessException e) {
			throw new InternalConfigurationException("Failed to set service fields"e);
catch (SecurityException e) {
			throw new InternalConfigurationException("Failed to set service fields"e);
catch (IllegalArgumentException e) {
			throw new InternalConfigurationException("Failed to set service fields"e);
		}
	}

Paginated list class for dashboards.
	private class DashboardList extends PaginatedIdListImpl<DashboardInfo> {
		public DashboardList() {
			super(BellaDatiServiceImpl.this"api/dashboards""dashboards");
		}
		protected DashboardInfo parse(BellaDatiServiceImpl serviceJsonNode node) {
			return new DashboardInfoImpl(servicenode);
		}
	}

Paginated list class for reports.
	private class ReportList extends PaginatedIdListImpl<ReportInfo> {
		public ReportList() {
			super(BellaDatiServiceImpl.this"api/reports""reports");
		}
		protected ReportInfo parse(BellaDatiServiceImpl serviceJsonNode node) {
			return new ReportInfoImpl(servicenode);
		}
	}

Paginated list class for data sets.
	private class DataSetList extends PaginatedIdListImpl<DataSetInfo> {
		public DataSetList() {
			super(BellaDatiServiceImpl.this"api/dataSets""dataSets");
		}
		protected DataSetInfo parse(BellaDatiServiceImpl serviceJsonNode node) {
			return new DataSetInfoImpl(servicenode);
		}
	}
New to GrepCode? Check out our FAQ X