
com.belladati.sdk.impl.DataSetImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-java Show documentation
Show all versions of sdk-java Show documentation
The BellaDati SDK allows accessing a BellaDati server from 3rd-party applications using Java. This project contains the implementation for standard Java.
The newest version!
package com.belladati.sdk.impl;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import com.belladati.sdk.dataset.Attribute;
import com.belladati.sdk.dataset.DataSet;
import com.belladati.sdk.dataset.Indicator;
import com.belladati.sdk.dataset.data.DataTable;
import com.belladati.sdk.dataset.source.DataSource;
import com.belladati.sdk.impl.AttributeImpl.InvalidAttributeException;
import com.belladati.sdk.impl.IndicatorImpl.InvalidIndicatorException;
import com.belladati.sdk.impl.ReportInfoImpl.InvalidReportException;
import com.belladati.sdk.report.ReportInfo;
import com.belladati.sdk.util.CachedList;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
class DataSetImpl implements DataSet {
private final BellaDatiServiceImpl service;
private final String id;
private final String name;
private final String description;
private final String ownerName;
private final Date lastChange;
private final List attributes;
private final List indicators;
private final List reports;
private final LocalizationImpl localization;
DataSetImpl(BellaDatiServiceImpl service, JsonNode json) {
this.service = service;
this.id = json.get("id").asText();
this.name = json.get("name").asText();
this.description = json.hasNonNull("description") ? json.get("description").asText() : "";
this.ownerName = json.get("owner").asText();
if (json.hasNonNull("lastChange")) {
SimpleDateFormat format = new SimpleDateFormat(BellaDatiServiceImpl.DATE_TIME_FORMAT);
Date lastChange;
try {
lastChange = format.parse(json.get("lastChange").asText());
} catch (ParseException e) {
lastChange = null;
}
this.lastChange = lastChange;
} else {
this.lastChange = null;
}
List attributes = new ArrayList();
if (json.hasNonNull("attributes") && json.get("attributes") instanceof ArrayNode) {
for (JsonNode attribute : (ArrayNode) json.get("attributes")) {
try {
attributes.add(new AttributeImpl(service, id, attribute));
} catch (InvalidAttributeException e) {
// nothing to do, just ignore the attribute
}
}
}
this.attributes = Collections.unmodifiableList(attributes);
List indicators = new ArrayList();
if (json.hasNonNull("indicators") && json.get("indicators") instanceof ArrayNode) {
for (JsonNode indicator : (ArrayNode) json.get("indicators")) {
try {
indicators.add(new IndicatorImpl(indicator));
} catch (InvalidIndicatorException e) {
// nothing to do, just ignore the indicator
}
}
}
this.indicators = Collections.unmodifiableList(indicators);
List reports = new ArrayList();
if (json.hasNonNull("reports") && json.get("reports") instanceof ArrayNode) {
for (JsonNode report : (ArrayNode) json.get("reports")) {
try {
reports.add(new ReportInfoImpl(service, report));
} catch (InvalidReportException e) {
// nothing to do, just ignore the report
}
}
}
this.reports = Collections.unmodifiableList(reports);
this.localization = new LocalizationImpl(json);
}
@Override
public String getId() {
return id;
}
@Override
public String getName() {
return name;
}
@Override
public String getName(Locale locale) {
return localization.getName(locale);
}
@Override
public boolean hasLocalization(Locale locale) {
return localization.hasLocalization(locale);
}
@Override
public String getDescription() {
return description;
}
@Override
public String getOwnerName() {
return ownerName;
}
@Override
public Date getLastChange() {
return lastChange != null ? (Date) lastChange.clone() : null;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof DataSetImpl) {
return id.equals(((DataSetImpl) obj).id);
}
return false;
}
@Override
public int hashCode() {
return id.hashCode();
}
@Override
public List getAttributes() {
return attributes;
}
@Override
public List getIndicators() {
return indicators;
}
@Override
public List getReports() {
return reports;
}
@Override
public CachedList getDataSources() {
return service.getDataSources(id);
}
@Override
public DataTable createDataTable() {
List columns = new ArrayList();
for (Attribute attribute : attributes) {
columns.add(attribute.getCode());
}
for (Indicator indicator : indicators) {
columns.add(indicator.getCode());
}
return DataTable.createBasicInstance(columns);
}
@Override
public DataSet uploadData(DataTable data) {
service.uploadData(id, data);
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy