Skip to content

Commit 4e92f0f

Browse files
authored
Merge pull request #589 from gooddata/lcm
introduce LcmService
2 parents 4b89e37 + ef3d896 commit 4e92f0f

13 files changed

Lines changed: 675 additions & 0 deletions

src/main/java/com/gooddata/GoodData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.gooddata.export.ExportService;
1515
import com.gooddata.featureflag.FeatureFlagService;
1616
import com.gooddata.gdc.Header;
17+
import com.gooddata.lcm.LcmService;
1718
import com.gooddata.md.maintenance.ExportImportService;
1819
import com.gooddata.notification.NotificationService;
1920
import com.gooddata.projecttemplate.ProjectTemplateService;
@@ -95,6 +96,7 @@ public class GoodData {
9596
private final ExportService exportService;
9697
private final AuditEventService auditEventService;
9798
private final ExecuteAfmService executeAfmService;
99+
private final LcmService lcmService;
98100

99101
/**
100102
* Create instance configured to communicate with GoodData Platform under user with given credentials.
@@ -232,6 +234,7 @@ protected GoodData(GoodDataEndpoint endpoint, Authentication authentication, Goo
232234
projectTemplateService = new ProjectTemplateService(getRestTemplate(), settings);
233235
auditEventService = new AuditEventService(getRestTemplate(), accountService, settings);
234236
executeAfmService = new ExecuteAfmService(getRestTemplate(), settings);
237+
lcmService = new LcmService(getRestTemplate(), settings);
235238
}
236239

237240
static RestTemplate createRestTemplate(GoodDataEndpoint endpoint, HttpClient httpClient) {
@@ -507,5 +510,14 @@ public ExecuteAfmService getExecuteAfmService() {
507510
return executeAfmService;
508511
}
509512

513+
/**
514+
* Get initialized service for Life Cycle Management
515+
* @return initialized service for Life Cycle Management
516+
*/
517+
@Bean
518+
public LcmService getLcmService() {
519+
return lcmService;
520+
}
521+
510522

511523
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2007-2018, 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.lcm;
7+
8+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
9+
import com.fasterxml.jackson.annotation.JsonInclude;
10+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
11+
import com.fasterxml.jackson.annotation.JsonTypeName;
12+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
13+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
14+
import com.gooddata.collections.PageableList;
15+
import com.gooddata.collections.PageableListDeserializer;
16+
import com.gooddata.collections.PageableListSerializer;
17+
import com.gooddata.collections.Paging;
18+
import org.springframework.web.util.UriTemplate;
19+
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
import static java.util.Arrays.asList;
24+
25+
/**
26+
* List of {@link LcmEntity}.
27+
*/
28+
@JsonDeserialize(using = LcmEntities.Deserializer.class)
29+
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
30+
@JsonTypeName(LcmEntities.ROOT_NODE)
31+
@JsonIgnoreProperties(ignoreUnknown = true)
32+
@JsonSerialize(using = LcmEntities.Serializer.class)
33+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
34+
public class LcmEntities extends PageableList<LcmEntity> {
35+
36+
public static final String URI = "/gdc/account/profile/{profileId}/lcmEntities";
37+
public static final UriTemplate TEMPLATE = new UriTemplate(URI);
38+
39+
static final String ROOT_NODE = "lcmEntities";
40+
41+
public LcmEntities(final List<LcmEntity> items, final Paging paging, final Map<String, String> links) {
42+
super(items, paging, links);
43+
}
44+
45+
LcmEntities(final LcmEntity... lcmEntities) {
46+
this(asList(lcmEntities), null, null);
47+
}
48+
49+
static class Serializer extends PageableListSerializer {
50+
public Serializer() {
51+
super(ROOT_NODE);
52+
}
53+
}
54+
55+
static class Deserializer extends PageableListDeserializer<LcmEntities, LcmEntity> {
56+
protected Deserializer() {
57+
super(LcmEntity.class);
58+
}
59+
60+
@Override
61+
protected LcmEntities createList(final List<LcmEntity> items, final Paging paging, final Map<String, String> links) {
62+
return new LcmEntities(items, paging, links);
63+
}
64+
}
65+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright (C) 2007-2018, 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.lcm;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonIgnore;
10+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
11+
import com.fasterxml.jackson.annotation.JsonInclude;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import com.gooddata.util.GoodDataToStringBuilder;
14+
15+
import java.util.Map;
16+
import java.util.Objects;
17+
18+
import static com.gooddata.lcm.LcmEntity.LinkCategory.CLIENT;
19+
import static com.gooddata.lcm.LcmEntity.LinkCategory.DATA_PRODUCT;
20+
import static com.gooddata.lcm.LcmEntity.LinkCategory.PROJECT;
21+
import static com.gooddata.lcm.LcmEntity.LinkCategory.SEGMENT;
22+
import static com.gooddata.util.Validate.notEmpty;
23+
import static com.gooddata.util.Validate.notNull;
24+
import static com.gooddata.util.Validate.notNullState;
25+
26+
/**
27+
* Single Life Cycle Management entity representing the relation between {@link com.gooddata.project.Project},
28+
* Client, Segment and DataProduct.
29+
*/
30+
@JsonIgnoreProperties(ignoreUnknown = true)
31+
@JsonInclude(JsonInclude.Include.NON_NULL)
32+
public class LcmEntity {
33+
34+
private final String projectId;
35+
private final String projectTitle;
36+
private final String clientId;
37+
private final String segmentId;
38+
private final String dataProductId;
39+
private final Map<String, String> links;
40+
41+
/**
42+
* Creates new instance of given project id and title
43+
* @param projectId id of the project
44+
* @param projectTitle title of the project
45+
* @param links links
46+
*/
47+
public LcmEntity(final String projectId, final String projectTitle, final Map<String, String> links) {
48+
this(projectId, projectTitle, null, null, null, links);
49+
}
50+
51+
@JsonCreator
52+
public LcmEntity(@JsonProperty("projectId") final String projectId,
53+
@JsonProperty("projectTitle") final String projectTitle,
54+
@JsonProperty("clientId") final String clientId,
55+
@JsonProperty("segmentId") final String segmentId,
56+
@JsonProperty("dataProductId") final String dataProductId,
57+
@JsonProperty("links") final Map<String, String> links) {
58+
this.projectId = notEmpty(projectId, "projectId");
59+
this.projectTitle = notNull(projectTitle, "projectTitle");
60+
this.clientId = clientId;
61+
this.segmentId = segmentId;
62+
this.dataProductId = dataProductId;
63+
this.links = notNull(links, "links");
64+
}
65+
66+
public String getProjectId() {
67+
return projectId;
68+
}
69+
70+
public String getProjectTitle() {
71+
return projectTitle;
72+
}
73+
74+
public String getClientId() {
75+
return clientId;
76+
}
77+
78+
public String getSegmentId() {
79+
return segmentId;
80+
}
81+
82+
public String getDataProductId() {
83+
return dataProductId;
84+
}
85+
86+
public Map<String, String> getLinks() {
87+
return links;
88+
}
89+
90+
@JsonIgnore
91+
public String getProjectUri() {
92+
return getLink(PROJECT);
93+
}
94+
95+
@JsonIgnore
96+
public String getClientUri() {
97+
return getLink(CLIENT);
98+
}
99+
100+
@JsonIgnore
101+
public String getSegmentUri() {
102+
return getLink(SEGMENT);
103+
}
104+
105+
@JsonIgnore
106+
public String getDataProductUri() {
107+
return getLink(DATA_PRODUCT);
108+
}
109+
110+
private String getLink(final String link) {
111+
return notNullState(links, "links").get(link);
112+
}
113+
114+
@Override
115+
public boolean equals(final Object o) {
116+
if (this == o) return true;
117+
if (o == null || getClass() != o.getClass()) return false;
118+
final LcmEntity lcmEntity = (LcmEntity) o;
119+
return Objects.equals(projectId, lcmEntity.projectId) &&
120+
Objects.equals(projectTitle, lcmEntity.projectTitle) &&
121+
Objects.equals(clientId, lcmEntity.clientId) &&
122+
Objects.equals(segmentId, lcmEntity.segmentId) &&
123+
Objects.equals(dataProductId, lcmEntity.dataProductId) &&
124+
Objects.equals(links, lcmEntity.links);
125+
}
126+
127+
@Override
128+
public int hashCode() {
129+
130+
return Objects.hash(projectId, projectTitle, clientId, segmentId, dataProductId, links);
131+
}
132+
133+
@Override
134+
public String toString() {
135+
return GoodDataToStringBuilder.defaultToString(this);
136+
}
137+
138+
public static class LinkCategory {
139+
public static final String PROJECT = "project";
140+
public static final String CLIENT = "client";
141+
public static final String SEGMENT = "segment";
142+
public static final String DATA_PRODUCT = "dataProduct";
143+
}
144+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (C) 2007-2018, 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.lcm;
7+
8+
import org.springframework.util.LinkedMultiValueMap;
9+
import org.springframework.util.MultiValueMap;
10+
11+
import static java.util.Collections.singletonList;
12+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
13+
14+
/**
15+
* Specification of the filter on {@link LcmEntities}.
16+
*/
17+
public class LcmEntityFilter {
18+
19+
private static final String DATA_PRODUCT = "dataProduct";
20+
private static final String SEGMENT = "segment";
21+
private static final String CLIENT = "client";
22+
23+
private String dataProduct;
24+
private String segment;
25+
private String client;
26+
27+
/**
28+
* Creates new (empty) filter.
29+
*/
30+
public LcmEntityFilter() {
31+
}
32+
33+
/**
34+
* Adds given data product to this filter.
35+
* @param dataProduct data product id - must not be empty.
36+
* @return this filter
37+
*/
38+
public LcmEntityFilter withDataProduct(final String dataProduct) {
39+
if (isNotBlank(dataProduct)) {
40+
this.dataProduct = dataProduct;
41+
}
42+
return this;
43+
}
44+
45+
/**
46+
* Adds given segment to this filter.
47+
* @param segment segment id - must not be empty.
48+
* @return this filter
49+
*/
50+
public LcmEntityFilter withSegment(final String segment) {
51+
if (isNotBlank(segment)) {
52+
this.segment = segment;
53+
}
54+
return this;
55+
}
56+
57+
/**
58+
* Adds given client to this filter.
59+
* @param client client id - must not be empty.
60+
* @return this filter
61+
*/
62+
public LcmEntityFilter withClient(final String client) {
63+
if (isNotBlank(client)) {
64+
this.client = client;
65+
}
66+
return this;
67+
}
68+
69+
public String getDataProduct() {
70+
return dataProduct;
71+
}
72+
73+
public String getSegment() {
74+
return segment;
75+
}
76+
77+
public String getClient() {
78+
return client;
79+
}
80+
81+
/**
82+
* This filter in the form of query parameters map.
83+
* @return filter as query params map
84+
*/
85+
public MultiValueMap<String, String> asQueryParams() {
86+
final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
87+
if (dataProduct != null) {
88+
params.put(DATA_PRODUCT, singletonList(dataProduct));
89+
}
90+
if (segment != null) {
91+
params.put(SEGMENT, singletonList(segment));
92+
}
93+
if (client != null) {
94+
params.put(CLIENT, singletonList(client));
95+
}
96+
return params;
97+
}
98+
}

0 commit comments

Comments
 (0)