Skip to content

Commit e7622df

Browse files
author
gdgate
authored
Merge pull request #966 from gooddata/export
Add export/import of the whole project Reviewed-by: Peter Plocháň https://github.com/peter-plochan
2 parents f32694f + 560c4ee commit e7622df

File tree

19 files changed

+639
-29
lines changed

19 files changed

+639
-29
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (C) 2004-2020, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.sdk.model.md.maintenance;
7+
8+
import com.fasterxml.jackson.annotation.JsonInclude;
9+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
10+
import com.fasterxml.jackson.annotation.JsonTypeName;
11+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
12+
import com.gooddata.sdk.common.util.BooleanStringSerializer;
13+
import com.gooddata.sdk.common.util.GoodDataToStringBuilder;
14+
15+
import java.util.Collection;
16+
import java.util.HashSet;
17+
18+
import static com.gooddata.sdk.common.util.Validate.notEmpty;
19+
import static java.util.Arrays.asList;
20+
21+
/**
22+
* Complete project export configuration structure.
23+
* Serialization only.
24+
*/
25+
@JsonTypeName("exportProject")
26+
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
27+
@JsonInclude(JsonInclude.Include.NON_NULL)
28+
public class ExportProject {
29+
30+
public static final String URI = "/gdc/md/{projectId}/maintenance/export";
31+
32+
private final boolean exportUsers;
33+
private final boolean exportData;
34+
private final boolean excludeSchedules;
35+
private final boolean crossDataCenterExport;
36+
private final String authorizedUsers;
37+
38+
/**
39+
* Creates new ExportProject with default settings.
40+
* Sets exportUsers=true exportData=true, excludeSchedules=false, crossDataCenterExport=false and empty authorizedUsers.
41+
*/
42+
public ExportProject() {
43+
this(true, true, false, false, null);
44+
}
45+
46+
/**
47+
* Creates new ExportProject.
48+
*
49+
* @param exportUsers whether to add necessary data to be able to clone attribute properties
50+
* @param exportData whether to add necessary data to be able to clone attribute properties
51+
* @param excludeSchedules whether to add necessary data to be able to clone attribute properties
52+
* @param crossDataCenterExport whether export should be usable in any Data Center
53+
* @param authorizedUsers comma-separated list of email addresses of users authorized to import the project, surround email addresses with double quotes
54+
*/
55+
public ExportProject(final boolean exportUsers, final boolean exportData, final boolean excludeSchedules, final boolean crossDataCenterExport, final String authorizedUsers) {
56+
this.exportUsers = exportUsers;
57+
this.exportData = exportData;
58+
this.excludeSchedules = excludeSchedules;
59+
this.crossDataCenterExport = crossDataCenterExport;
60+
this.authorizedUsers = authorizedUsers;
61+
}
62+
63+
@JsonSerialize(using = BooleanStringSerializer.class)
64+
public boolean isExportUsers() {
65+
return exportUsers;
66+
}
67+
68+
@JsonSerialize(using = BooleanStringSerializer.class)
69+
public boolean isExportData() {
70+
return exportData;
71+
}
72+
73+
@JsonSerialize(using = BooleanStringSerializer.class)
74+
public boolean isExcludeSchedules() {
75+
return excludeSchedules;
76+
}
77+
78+
@JsonSerialize(using = BooleanStringSerializer.class)
79+
public boolean isCrossDataCenterExport() {
80+
return crossDataCenterExport;
81+
}
82+
83+
public String getAuthorizedUsers() {
84+
return authorizedUsers;
85+
}
86+
87+
@Override
88+
public String toString() {
89+
return GoodDataToStringBuilder.defaultToString(this);
90+
}
91+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2004-2020, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.sdk.model.md.maintenance;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
import com.fasterxml.jackson.annotation.JsonTypeName;
11+
import com.gooddata.sdk.model.gdc.UriResponse;
12+
13+
/**
14+
* Complete project export result structure.
15+
* For internal use only.
16+
* Deserialization only.
17+
*/
18+
@JsonTypeName("exportArtifact")
19+
public class ExportProjectArtifact extends PartialMdArtifact {
20+
21+
@JsonCreator
22+
public ExportProjectArtifact(@JsonProperty("status") UriResponse status, @JsonProperty("token") String token) {
23+
super(status, token);
24+
}
25+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2004-2020, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.sdk.model.md.maintenance;
7+
8+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
9+
import com.fasterxml.jackson.annotation.JsonTypeName;
10+
import com.gooddata.sdk.common.util.GoodDataToStringBuilder;
11+
12+
import static com.gooddata.sdk.common.util.Validate.notEmpty;
13+
14+
/**
15+
* Complete project export token. Serves as configuration structure for import.
16+
* Serialization only.
17+
*/
18+
@JsonTypeName("importProject")
19+
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
20+
public class ExportProjectToken {
21+
22+
public static final String URI = "/gdc/md/{projectId}/maintenance/import";
23+
24+
private final String token;
25+
26+
/**
27+
* Creates new ExportProjectToken.
28+
*
29+
* @param token token identifying export of another project
30+
*/
31+
public ExportProjectToken(String token) {
32+
this.token = notEmpty(token, "token");
33+
}
34+
35+
public String getToken() {
36+
return token;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return GoodDataToStringBuilder.defaultToString(this);
42+
}
43+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2004-2020, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.sdk.model.md.maintenance;
7+
8+
import com.gooddata.sdk.model.gdc.UriResponse;
9+
import org.testng.annotations.Test;
10+
11+
import static com.gooddata.sdk.common.util.ResourceUtils.readObjectFromResource;
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.hamcrest.Matchers.is;
14+
import static org.hamcrest.text.MatchesPattern.matchesPattern;
15+
16+
public class ExportProjectArtifactTest {
17+
18+
@Test
19+
public void shouldDeserialize() throws Exception {
20+
final ExportProjectArtifact exportProjectArtifact = readObjectFromResource("/md/maintenance/exportArtifact.json",
21+
ExportProjectArtifact.class);
22+
23+
assertThat(exportProjectArtifact.getStatusUri(), is("/gdc/md/projectId/tasks/taskId/status"));
24+
assertThat(exportProjectArtifact.getToken(), is("TOKEN123"));
25+
}
26+
27+
@Test
28+
public void testToStringFormat() {
29+
final ExportProjectArtifact exportProjectArtifact = new ExportProjectArtifact(
30+
new UriResponse("/gdc/md/projectId/tasks/taskId/status"), "TOKEN123");
31+
32+
assertThat(exportProjectArtifact.toString(), matchesPattern(ExportProjectArtifact.class.getSimpleName() + "\\[.*\\]"));
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2004-2020, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.sdk.model.md.maintenance;
7+
8+
import org.testng.annotations.Test;
9+
10+
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
11+
import static net.javacrumbs.jsonunit.core.util.ResourceUtils.resource;
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.hamcrest.text.MatchesPattern.matchesPattern;
14+
15+
public class ExportProjectTest {
16+
17+
@Test
18+
public void shouldSerialize() {
19+
final ExportProject exportProject = new ExportProject(false, false, true, true, "test");
20+
21+
assertThat(exportProject, jsonEquals(resource("md/maintenance/exportProject.json")));
22+
}
23+
24+
@Test
25+
public void shouldSerializeDefaultValues() {
26+
final ExportProject exportProject = new ExportProject();
27+
28+
assertThat(exportProject, jsonEquals(resource("md/maintenance/exportProject-defaultVals.json")));
29+
}
30+
31+
@Test
32+
public void testToStringFormat() {
33+
final ExportProject exportProject = new ExportProject();
34+
35+
assertThat(exportProject.toString(), matchesPattern(ExportProject.class.getSimpleName() + "\\[.*\\]"));
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2004-2020, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.sdk.model.md.maintenance;
7+
8+
import org.testng.annotations.Test;
9+
10+
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
11+
import static net.javacrumbs.jsonunit.core.util.ResourceUtils.resource;
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.hamcrest.text.MatchesPattern.matchesPattern;
14+
15+
public class ExportProjectTokenTest {
16+
17+
@Test
18+
public void shouldSerialize() {
19+
final ExportProjectToken exportProjectToken = new ExportProjectToken("TOKEN123");
20+
21+
assertThat(exportProjectToken, jsonEquals(resource("md/maintenance/importProject.json")));
22+
}
23+
24+
@Test
25+
public void testToStringFormat() {
26+
final ExportProjectToken exportProjectToken = new ExportProjectToken("TOKEN123");
27+
28+
assertThat(exportProjectToken.toString(), matchesPattern(ExportProjectToken.class.getSimpleName() + "\\[.*\\]"));
29+
}
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"exportArtifact": {
3+
"status": {
4+
"uri": "/gdc/md/projectId/tasks/taskId/status"
5+
},
6+
"token": "TOKEN123"
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"exportProject": {
3+
"exportUsers": "1",
4+
"exportData": "1",
5+
"excludeSchedules": "0",
6+
"crossDataCenterExport": "0"
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"exportProject": {
3+
"exportUsers": "0",
4+
"exportData": "0",
5+
"excludeSchedules": "1",
6+
"crossDataCenterExport": "1",
7+
"authorizedUsers": "test"
8+
}
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"importProject": {
3+
"token": "TOKEN123"
4+
}
5+
}

0 commit comments

Comments
 (0)