Skip to content

Commit e3c9985

Browse files
committed
allow to specify identifier when creating object
Close: gooddata#508
1 parent c7f192c commit e3c9985

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/main/java/com/gooddata/md/MetadataService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public <T extends Obj> T createObj(Project project, T obj) {
5252

5353
final T response;
5454
try {
55-
response = restTemplate.postForObject(Obj.CREATE_URI, obj, (Class<T>)obj.getClass(), project.getId());
55+
response = restTemplate.postForObject(Obj.CREATE_WITH_ID_URI, obj, (Class<T>)obj.getClass(), project.getId());
5656
} catch (GoodDataRestException | RestClientException e) {
5757
throw new ObjCreateException(obj, e);
5858
}

src/main/java/com/gooddata/md/Obj.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface Obj {
1414

1515
String URI = "/gdc/md/{projectId}/obj";
1616
String CREATE_URI = URI + "?createAndGet=true";
17+
String CREATE_WITH_ID_URI = CREATE_URI + "&setIdentifier=true";
1718
String OBJ_URI = URI + "/{objId}";
1819
UriTemplate OBJ_TEMPLATE = new UriTemplate(OBJ_URI);
1920

src/test/java/com/gooddata/md/MetadataServiceAT.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public void updateObj() throws Exception {
5959
@Test(groups = "md", dependsOnMethods = "getObjs")
6060
public void createMetric() throws Exception {
6161
final MetadataService md = gd.getMetadataService();
62-
metric = md.createObj(project, new Metric("Avg shoe size", "SELECT AVG([" + fact + "])", "#,##0"));
62+
final Metric create = new Metric("Avg shoe size", "SELECT AVG([" + fact + "])", "#,##0");
63+
create.setIdentifier("metric.avgshoesize");
64+
metric = md.createObj(project, create);
65+
assertThat(metric.getIdentifier(), is("metric.avgshoesize"));
6366
}
6467

6568
@Test(groups = "md", dependsOnMethods = "createMetric")

src/test/java/com/gooddata/md/MetadataServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testCreateObj() throws Exception {
8585
final Obj obj = mock(Obj.class);
8686
final Obj resultObj = mock(Obj.class);
8787

88-
when(restTemplate.postForObject(eq(Obj.CREATE_URI), eq(obj), Matchers.<Class<Obj>>any(), eq(PROJECT_ID)))
88+
when(restTemplate.postForObject(eq(Obj.CREATE_WITH_ID_URI), eq(obj), Matchers.<Class<Obj>>any(), eq(PROJECT_ID)))
8989
.thenReturn(resultObj);
9090

9191
final Obj result = service.createObj(project, obj);

0 commit comments

Comments
 (0)