Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
1.2.62 & adjusted to the metadata changes in R83
Browse files Browse the repository at this point in the history
  • Loading branch information
zsvoboda committed Oct 25, 2012
1 parent b67779a commit 15a6dca
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 155 deletions.
2 changes: 1 addition & 1 deletion backend/pom.xml
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>com.gooddata.cl</groupId>
<artifactId>gooddata-cl</artifactId>
<version>1.2.61</version>
<version>1.2.62</version>
</parent>

<artifactId>gooddata-cl-backend</artifactId>
Expand Down
Expand Up @@ -768,83 +768,6 @@ public List<String> enumerateReports(String projectId) {
return list;
}

/**
* Gets a report definition from the report uri (/gdc/obj...)
*
* @param reportUri report uri (/gdc/obj...)
* @return report definition
*/
public String getReportDefinition(String reportUri) {
l.debug( "Getting report definition for report uri=" + reportUri );
String qUri = getServerUrl() + reportUri;
HttpMethod qGet = createGetMethod( qUri );
try {
String qr = executeMethodOk( qGet );
JSONObject q = JSONObject.fromObject( qr );
if (q.isNullObject()) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
JSONObject report = q.getJSONObject("report");
if (report.isNullObject()) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
JSONObject content = report.getJSONObject("content");
if (content.isNullObject()) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
JSONArray results = content.getJSONArray("results");
if (results == null) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
if (results.size() > 0) {
String lastResultUri = results.getString(results.size() - 1);
qUri = getServerUrl() + lastResultUri;
qGet = createGetMethod(qUri);
GetMethod qGet2 = createGetMethod( qUri );
try
{
qr = executeMethodOk( qGet2 );
q = JSONObject.fromObject(qr);
if (q.isNullObject()) {
l.debug("Error getting report definition for result uri=" + lastResultUri);
throw new GdcProjectAccessException("Error getting report definition for result uri=" + lastResultUri);
}
JSONObject result = q.getJSONObject("reportResult2");
if (result.isNullObject()) {
l.debug("Error getting report definition for result uri=" + lastResultUri);
throw new GdcProjectAccessException("Error getting report definition for result uri=" + lastResultUri);
}
content = result.getJSONObject("content");
if (result.isNullObject()) {
l.debug("Error getting report definition for result uri=" + lastResultUri);
throw new GdcProjectAccessException("Error getting report definition for result uri=" + lastResultUri);
}
return content.getString("reportDefinition");
}
finally
{
qGet2.releaseConnection();
}
}
// Here we haven't found any results. Let's try the defaultReportDefinition
if (content.containsKey("defaultReportDefinition")) {
String defaultRepDef = content.getString("defaultReportDefinition");
if (defaultRepDef != null && defaultRepDef.length() > 0)
return defaultRepDef;
}
l.debug("Error getting report definition for report uri=" + reportUri + " . No report results!");
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri +
" . No report results!");
} finally {
if (qGet != null)
qGet.releaseConnection();
}
}

private String getProjectIdFromObjectUri(String uri) {
Pattern regexp = Pattern.compile("gdc/md/.*?/");
Matcher m = regexp.matcher(uri);
Expand Down Expand Up @@ -951,12 +874,11 @@ public double computeMetric(String metricUri) {
public String computeReport(String reportUri) {
l.debug("Computing report uri=" + reportUri);
String retVal = "";
String reportDefUri = getReportDefinition(reportUri);
int retryCnt = 1000;
boolean hasFinished = false;
while (retryCnt-- > 0 && !hasFinished) {
try {
String dataResultUri = executeReportDefinition(reportDefUri);
String dataResultUri = executeReport(reportUri);
JSONObject result = getObjectByUri(dataResultUri);
hasFinished = true;
if (result != null && !result.isEmpty() && !result.isNullObject()) {
Expand Down Expand Up @@ -1075,7 +997,6 @@ public String executeReportDefinition(String reportDefUri) {
exec.put("report_req", execDef);
InputStreamRequestEntity request = new InputStreamRequestEntity(new ByteArrayInputStream(exec.toString().getBytes()));
execPost.setRequestEntity(request);
String taskLink = null;
try {
String task = executeMethodOk(execPost);
if (task != null && task.length() > 0) {
Expand All @@ -1085,19 +1006,19 @@ public String executeReportDefinition(String reportDefUri) {
throw new GdcRestApiException("Executing report definition uri=" + reportDefUri + " failed. " +
"Returned invalid result result=" + tr);
}
JSONObject reportResult = tr.getJSONObject("reportResult2");
JSONObject reportResult = tr.getJSONObject("execResult");
if (reportResult.isNullObject()) {
l.debug("Executing report definition uri=" + reportDefUri + " failed. Returned invalid result result=" + tr);
throw new GdcRestApiException("Executing report definition uri=" + reportDefUri + " failed. " +
"Returned invalid result result=" + tr);
}
JSONObject content = reportResult.getJSONObject("content");
if (content.isNullObject()) {
String dataResult = reportResult.getString("dataResult");
if (dataResult == null || dataResult.length()<=0) {
l.debug("Executing report definition uri=" + reportDefUri + " failed. Returned invalid result result=" + tr);
throw new GdcRestApiException("Executing report definition uri=" + reportDefUri + " failed. " +
"Returned invalid result result=" + tr);
}
return content.getString("dataResult");
return dataResult;
} else {
l.debug("Executing report definition uri=" + reportDefUri + " failed. Returned invalid task link uri=" + task);
throw new GdcRestApiException("Executing report definition uri=" + reportDefUri +
Expand Down Expand Up @@ -1135,19 +1056,19 @@ public String executeReport(String reportUri) {
throw new GdcRestApiException("Executing report uri=" + reportUri + " failed. " +
"Returned invalid result result=" + tr);
}
JSONObject reportResult = tr.getJSONObject("reportResult2");
JSONObject reportResult = tr.getJSONObject("execResult");
if (reportResult.isNullObject()) {
l.debug("Executing report uri=" + reportUri + " failed. Returned invalid result=" + tr);
throw new GdcRestApiException("Executing report uri=" + reportUri + " failed. " +
"Returned invalid result result=" + tr);
}
JSONObject meta = reportResult.getJSONObject("meta");
if (meta.isNullObject()) {
l.debug("Executing report uri=" + reportUri + " failed. Returned invalid result=" + tr);
String dataResult = reportResult.getString("dataResult");
if (dataResult == null || dataResult.length()<=0) {
l.debug("Executing report uri=" + reportUri + " failed. Returned invalid dataResult=" + tr);
throw new GdcRestApiException("Executing report uri=" + reportUri + " failed. " +
"Returned invalid result=" + tr);
"Returned invalid dataResult=" + tr);
}
return meta.getString("uri");
return dataResult;
} else {
l.debug("Executing report uri=" + reportUri + " failed. Returned invalid task link uri=" + task);
throw new GdcRestApiException("Executing report uri=" + reportUri +
Expand Down Expand Up @@ -2739,16 +2660,6 @@ public JSONObject getObjectByUri(String objectUri) {
public MetadataObject getMetadataObject(String objectUri) {
l.debug("Executing getMetadataObject uri=" + objectUri);
MetadataObject o = new MetadataObject(getObjectByUri(objectUri));
String tp = o.getType();
if (tp.equalsIgnoreCase("report")) {
try {
String rdf = getReportDefinition(objectUri);
JSONObject c = o.getContent();
c.put("defaultReportDefinition", rdf);
} catch (GdcProjectAccessException e) {
l.debug("Can't extract the default report definition.");
}
}
return o;
}

Expand Down Expand Up @@ -3101,7 +3012,7 @@ private static <T extends HttpMethod> T configureHttpMethod(T request) {
request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Accept-Charset", "utf-u");
request.setRequestHeader("User-Agent", "GoodData CL/1.2.61");
request.setRequestHeader("User-Agent", "GoodData CL/1.2.62");
return request;
}

Expand Down Expand Up @@ -3412,4 +3323,56 @@ public List<Project> listProjects() throws HttpMethodException {
l.debug("Found projects " + list);
return list;
}

/**
* Gets a report definition from the report uri (/gdc/obj...)
*
* @param reportUri report uri (/gdc/obj...)
* @return report definition
*/
@Deprecated
public String getReportDefinition(String reportUri) {
l.debug( "Getting report definition for report uri=" + reportUri );
String qUri = getServerUrl() + reportUri;
HttpMethod qGet = createGetMethod( qUri );
try {
String qr = executeMethodOk( qGet );
JSONObject q = JSONObject.fromObject( qr );
if (q.isNullObject()) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
JSONObject report = q.getJSONObject("report");
if (report.isNullObject()) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
JSONObject content = report.getJSONObject("content");
if (content.isNullObject()) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
JSONArray definitions = content.getJSONArray("definitions");
if (definitions == null) {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
if (definitions.size() > 0) {
String lastDefUri = definitions.getString(definitions.size() - 1);
qUri = getServerUrl() + lastDefUri;
return lastDefUri;
}
else {
l.debug("Error getting report definition for report uri=" + reportUri);
throw new GdcProjectAccessException("Error getting report definition for report uri=" + reportUri);
}
} finally {
if (qGet != null)
qGet.releaseConnection();
}
}


}


Expand Up @@ -40,37 +40,60 @@ public class TestGdcRestApiWrapper extends TestCase {

private static Logger l = Logger.getLogger(TestGdcRestApiWrapper.class);

NamePasswordConfiguration config = null;
//NamePasswordConfiguration config = null;

//NamePasswordConfiguration config = new NamePasswordConfiguration("https","secure.gooddata.com","zd@gooddata.com","xxx");
NamePasswordConfiguration config = new NamePasswordConfiguration("https","js-rrrrd-devel.getgooddata.com","bear@gooddata.com","jindrisska");

String[] checkUrls = {
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/4170",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/12238",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/5479",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/13344",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/7261",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/12218",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/1788",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/13928",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/4148",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/8067",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/16843",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/3392",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/4192",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/4499",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/13772",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/18799",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/10730",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/6833",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/12467",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/7456",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/13785",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/4228",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/13876",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/3329",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/6826",
"/gdc/md/bd410owmaf3lks1qxtecwjpls340ckg5/obj/5138"
"/gdc/md/FoodMartDemo/obj/130003800",
"/gdc/md/FoodMartDemo/obj/130001937",
"/gdc/md/FoodMartDemo/obj/130002154",
"/gdc/md/FoodMartDemo/obj/130002361",
"/gdc/md/FoodMartDemo/obj/130002376",
"/gdc/md/FoodMartDemo/obj/130002297",
"/gdc/md/FoodMartDemo/obj/130002162",
"/gdc/md/FoodMartDemo/obj/130002654",
"/gdc/md/FoodMartDemo/obj/130002587",
"/gdc/md/FoodMartDemo/obj/130002121",
"/gdc/md/FoodMartDemo/obj/130002004",
"/gdc/md/FoodMartDemo/obj/130002614",
"/gdc/md/FoodMartDemo/obj/130002675",
"/gdc/md/FoodMartDemo/obj/130002632",
"/gdc/md/FoodMartDemo/obj/130002292",
"/gdc/md/FoodMartDemo/obj/130002187",
"/gdc/md/FoodMartDemo/obj/130002355",
"/gdc/md/FoodMartDemo/obj/130001832",
"/gdc/md/FoodMartDemo/obj/130002891",
"/gdc/md/FoodMartDemo/obj/130002151",
"/gdc/md/FoodMartDemo/obj/130002449",
"/gdc/md/FoodMartDemo/obj/130001911",
"/gdc/md/FoodMartDemo/obj/130001982",
"/gdc/md/FoodMartDemo/obj/130002111",
"/gdc/md/FoodMartDemo/obj/130002371",
"/gdc/md/FoodMartDemo/obj/130002310",
"/gdc/md/FoodMartDemo/obj/130002317",
"/gdc/md/FoodMartDemo/obj/130002188",
"/gdc/md/FoodMartDemo/obj/130002303",
"/gdc/md/FoodMartDemo/obj/130002024",
"/gdc/md/FoodMartDemo/obj/130002469",
"/gdc/md/FoodMartDemo/obj/130001892",
"/gdc/md/FoodMartDemo/obj/130002087",
"/gdc/md/FoodMartDemo/obj/130002505",
"/gdc/md/FoodMartDemo/obj/130001874",
"/gdc/md/FoodMartDemo/obj/130001844",
"/gdc/md/FoodMartDemo/obj/130002356",
"/gdc/md/FoodMartDemo/obj/130001858",
"/gdc/md/FoodMartDemo/obj/130002366",
"/gdc/md/FoodMartDemo/obj/130001967",
"/gdc/md/FoodMartDemo/obj/130002225",
"/gdc/md/FoodMartDemo/obj/130002209",
"/gdc/md/FoodMartDemo/obj/130002431",
"/gdc/md/FoodMartDemo/obj/130001900",
"/gdc/md/FoodMartDemo/obj/130002324",
"/gdc/md/FoodMartDemo/obj/130002567",
"/gdc/md/FoodMartDemo/obj/130002868",
"/gdc/md/FoodMartDemo/obj/130002036",
"/gdc/md/FoodMartDemo/obj/130002195"
};

public void testComputeMetric() throws Exception {
Expand All @@ -79,13 +102,8 @@ public void testComputeMetric() throws Exception {
GdcRESTApiWrapper rest = new GdcRESTApiWrapper(config);
rest.login();
for (String url : checkUrls) {
List<JSONObject> deps = rest.usedBy(url);
for (JSONObject d : deps) {
if ("report".equalsIgnoreCase(d.getString("category"))) {
System.out.println(d.getString("link") + " : " + d.getString("title"));
}
}

String value = rest.getReportDefinition(url);
System.out.println("Result "+value);
}
rest.logout();
}
Expand Down
2 changes: 1 addition & 1 deletion cli-distro/pom.xml
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>com.gooddata.cl</groupId>
<artifactId>gooddata-cl</artifactId>
<version>1.2.61</version>
<version>1.2.62</version>
</parent>

<artifactId>gooddata-cli</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion cli/pom.xml
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>com.gooddata.cl</groupId>
<artifactId>gooddata-cl</artifactId>
<version>1.2.61</version>
<version>1.2.62</version>
</parent>

<artifactId>gooddata-cl-cli</artifactId>
Expand Down
Expand Up @@ -267,7 +267,7 @@ protected CliParams parse(CommandLine ln) throws InvalidArgumentException {
CliParams cp = new CliParams();

if (cp.containsKey(CLI_PARAM_VERSION[0])) {
l.info("GoodData CL version 1.2.61");
l.info("GoodData CL version 1.2.62");
System.exit(0);
}

Expand Down

0 comments on commit 15a6dca

Please sign in to comment.