|
| 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 | +} |
0 commit comments