diff options
author | 2018-03-14 02:07:32 -0400 | |
---|---|---|
committer | 2018-03-14 04:08:41 -0400 | |
commit | 38f720752af4d4aad8c4e467a288d9048659f688 (patch) | |
tree | e81066a8b5c77272e30fb57a64999573c4db4d86 /common/src/main/java/org/openecomp/mso/client/aai/entities | |
parent | aee3d223f92a6f250f43e17558a2dfd576ff7294 (diff) |
AT&T 1712 and 1802 release code
This is code from AT&T's 1712 and 1802 releases.
Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04
Issue-ID: SO-425
Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'common/src/main/java/org/openecomp/mso/client/aai/entities')
22 files changed, 1621 insertions, 0 deletions
diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIEntity.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIEntity.java new file mode 100644 index 0000000000..3f0c4f3439 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIEntity.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +public class AAIEntity{ + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIEntityObject.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIEntityObject.java new file mode 100644 index 0000000000..e4a64c4161 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIEntityObject.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; + +public interface AAIEntityObject { + + public AAIResourceUri getUri(); + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIError.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIError.java new file mode 100644 index 0000000000..5f895ef862 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIError.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "requestError" +}) +public class AAIError { + + @JsonProperty("requestError") + private RequestError requestError; + + @JsonProperty("requestError") + public RequestError getRequestError() { + return requestError; + } + + @JsonProperty("requestError") + public void setRequestError(RequestError requestError) { + this.requestError = requestError; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIResultWrapper.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIResultWrapper.java new file mode 100644 index 0000000000..9898f04844 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/AAIResultWrapper.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.openecomp.mso.client.aai.AAICommonObjectMapperProvider; +import org.openecomp.mso.jsonpath.JsonPathUtil; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AAIResultWrapper { + + private final String jsonBody; + private final ObjectMapper mapper; + public AAIResultWrapper(String json) { + this.jsonBody = json; + this.mapper = new AAICommonObjectMapperProvider().getMapper(); + } + + public Optional<Relationships> getRelationships() { + final String path = "$.relationship-list"; + Optional<String> result = JsonPathUtil.getInstance().locateResult(jsonBody, path); + if (result.isPresent()) { + return Optional.of(new Relationships(result.get())); + } else { + return Optional.empty(); + } + } + + public String getJson() { + return jsonBody; + } + + public Map<String, Object> asMap() { + try { + return mapper.readValue(this.jsonBody, new TypeReference<Map<String, Object>>(){}); + } catch (IOException e) { + return new HashMap<>(); + } + } + + public <T> Optional<T> asBean(Class<T> clazz) { + try { + return Optional.of(mapper.readValue(this.jsonBody, clazz)); + } catch (IOException e) { + return Optional.empty(); + } + } + + @Override + public String toString() { + return this.getJson(); + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/Configuration.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/Configuration.java new file mode 100644 index 0000000000..a2d0fb3604 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/Configuration.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.mso.client.aai.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "configuration-id", + "configuration-type", + "configuration-sub-type", + "model-invariant-id", + "model-version-id", + "orchestration-status", + "operational-status", + "configuration-selflink", + "model-customization-id" +}) +public class Configuration { + + @JsonProperty("configuration-id") + private String configurationId; + @JsonProperty("configuration-name") + private String configurationName; + @JsonProperty("configuration-type") + private String configurationType; + @JsonProperty("configuration-sub-type") + private String configurationSubType; + @JsonProperty("model-invariant-id") + private String modelInvariantId; + @JsonProperty("model-version-id") + private String modelVersionId; + @JsonProperty("orchestration-status") + private String orchestrationStatus; + @JsonProperty("operational-status") + private String operationalStatus; + @JsonProperty("configuration-selflink") + private String configurationSelflink; + @JsonProperty("model-customization-id") + private String modelCustomizationId; + + @JsonProperty("configuration-id") + public String getConfigurationId() { + return configurationId; + } + + @JsonProperty("configuration-id") + public void setConfigurationId(String configurationId) { + this.configurationId = configurationId; + } + + @JsonProperty("configuration-name") + public String getConfigurationName() { + return configurationName; + } + + @JsonProperty("configuration-name") + public void setConfigurationName(String configurationName) { + this.configurationName = configurationName; + } + + @JsonProperty("configuration-type") + public String getConfigurationType() { + return configurationType; + } + + @JsonProperty("configuration-type") + public void setConfigurationType(String configurationType) { + this.configurationType = configurationType; + } + + @JsonProperty("configuration-sub-type") + public String getConfigurationSubType() { + return configurationSubType; + } + + @JsonProperty("configuration-sub-type") + public void setConfigurationSubType(String configurationSubType) { + this.configurationSubType = configurationSubType; + } + + @JsonProperty("model-invariant-id") + public String getModelInvariantId() { + return modelInvariantId; + } + + @JsonProperty("model-invariant-id") + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + @JsonProperty("model-version-id") + public String getModelVersionId() { + return modelVersionId; + } + + @JsonProperty("model-version-id") + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + @JsonProperty("orchestration-status") + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + @JsonProperty("orchestration-status") + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + + @JsonProperty("operational-status") + public String getOperationalStatus() { + return operationalStatus; + } + + @JsonProperty("operational-status") + public void setOperationalStatus(String operationalStatus) { + this.operationalStatus = operationalStatus; + } + + @JsonProperty("model-customization-id") + public String getModelCustomizationId() { + return modelCustomizationId; + } + + @JsonProperty("model-customization-id") + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } + + @JsonProperty("configuration-selflink") + public String getConfigurationSelflink() { + return configurationSelflink; + } + + @JsonProperty("configuration-selflink") + public void setConfigurationSelflink(String configurationSelflink) { + this.configurationSelflink = configurationSelflink; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/CustomQuery.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/CustomQuery.java new file mode 100644 index 0000000000..3d014b8f67 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/CustomQuery.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; + +import com.fasterxml.jackson.annotation.JsonInclude; + + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CustomQuery { + + private List<String> start; + private String query; + private String gremlin; + + public String getGremlin() { + return gremlin; + } + + public void setGremlin(String gremlin) { + this.gremlin = gremlin; + } + + + public CustomQuery(List<AAIResourceUri> start){ + this.setStart(start); + } + + public CustomQuery(List<AAIResourceUri> start, String query){ + this.setStart(start); + this.query= "query/" + query; + } + + public CustomQuery(String gremlin) throws UnsupportedEncodingException{ + this.gremlin=gremlin; + } + + public List<String> getStart() { + return start; + } + + public void setStart(List<AAIResourceUri> start) { + this.start = this.mapUris(start); + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + private List<String> mapUris(List<AAIResourceUri> uris) { + final List<String> result = new ArrayList<>(); + uris.stream().map(item -> item.build().toString()).forEach(result::add); + return result; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/Relationships.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/Relationships.java new file mode 100644 index 0000000000..cca2fb3744 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/Relationships.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Predicate; + +import javax.ws.rs.core.UriBuilder; + +import org.openecomp.mso.client.aai.AAICommonObjectMapperProvider; +import org.openecomp.mso.client.aai.AAIObjectName; +import org.openecomp.mso.client.aai.AAIObjectType; +import org.openecomp.mso.client.aai.AAIResourcesClient; +import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; +import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; +import org.openecomp.mso.jsonpath.JsonPathUtil; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.CaseFormat; + +public class Relationships { + + private final ObjectMapper mapper; + private Map<String, Object> map; + private final String jsonBody; + public Relationships(String json) { + this.jsonBody = json; + this.mapper = new AAICommonObjectMapperProvider().getMapper(); + try { + this.map = mapper.readValue(json, new TypeReference<Map<String, Object>>() {}); + } catch (IOException e) { + this.map = new HashMap<>(); + } + } + + public List<AAIResultWrapper> getByType(AAIObjectName type) { + + return this.getAll(Optional.of(type)); + } + + public List<AAIResultWrapper> getAll() { + + return this.getAll(Optional.empty()); + } + + + public List<String> getRelatedLinks() { + return this.getRelatedLinks(Optional.empty()); + } + + public List<String> getRelatedLinks(AAIObjectName type) { + return this.getRelatedLinks(Optional.of(type)); + } + + public List<AAIResourceUri> getRelatedAAIUris() { + return this.getRelatedAAIUris(x -> true); + } + + public List<AAIResourceUri> getRelatedAAIUris(AAIObjectName type) { + return this.getRelatedAAIUris(x -> type.typeName().equals(x)); + } + protected List<AAIResourceUri> getRelatedAAIUris(Predicate<String> p) { + List<AAIResourceUri> result = new ArrayList<>(); + if (map.containsKey("relationship")) { + List<Map<String, Object>> relationships = (List<Map<String, Object>>)map.get("relationship"); + for (Map<String, Object> relationship : relationships) { + final String relatedTo = (String)relationship.get("related-to"); + if (p.test(relatedTo)) { + AAIObjectType type; + try { + type = AAIObjectType.valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, relatedTo)); + } catch (IllegalArgumentException e) { + type = AAIObjectType.UNKNOWN; + } + final String relatedLink = (String)relationship.get("related-link"); + + result.add(AAIUriFactory.createResourceFromExistingURI(type, UriBuilder.fromPath(relatedLink).build())); + } + } + } + return result; + } + + + + protected List<AAIResultWrapper> getAll(final Optional<AAIObjectName> type) { + List<AAIResourceUri> relatedLinks; + if (type.isPresent()) { + relatedLinks = this.getRelatedAAIUris(type.get()); + } else { + relatedLinks = this.getRelatedAAIUris(); + } + ArrayList<AAIResultWrapper> result = new ArrayList<>(); + for (AAIResourceUri link : relatedLinks) { + result.add(this.get(link)); + } + return result; + } + + protected AAIResultWrapper get(AAIResourceUri uri) { + return new AAIResourcesClient().get(uri); + + } + + protected List<String> getRelatedLinks(Optional<AAIObjectName> type) { + String matcher = ""; + if (type.isPresent()) { + matcher = "[?(@.related-to=='" + type.get() + "')]"; + } + return JsonPathUtil.getInstance().locateResultList(this.jsonBody, String.format("$.relationship%s.related-link", matcher)); + } + + public String getJson() { + return this.jsonBody; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/RequestError.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/RequestError.java new file mode 100644 index 0000000000..2fd3572401 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/RequestError.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "serviceException" +}) +public class RequestError { + + @JsonProperty("serviceException") + private ServiceException serviceException; + + @JsonProperty("serviceException") + public ServiceException getServiceException() { + return serviceException; + } + + @JsonProperty("serviceException") + public void setServiceException(ServiceException serviceException) { + this.serviceException = serviceException; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/Results.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/Results.java new file mode 100644 index 0000000000..e91823a348 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/Results.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + + + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"results" +}) +public class Results<T> { + @JsonProperty("results") + protected List<T> results; + + @JsonProperty("results") + public List<T> getResult() { + if (results == null) { + results = new ArrayList<>(); + } + return this.results; + } + @JsonProperty("results") + public void setResult(List<T> results) { + this.results=results; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/ServiceException.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/ServiceException.java new file mode 100644 index 0000000000..66ca10d06b --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/ServiceException.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "messageId", + "text", + "variables" +}) +public class ServiceException { + + @JsonProperty("messageId") + private String messageId; + @JsonProperty("text") + private String text; + @JsonProperty("variables") + private List<String> variables = new ArrayList<>(); + + @JsonProperty("messageId") + public String getMessageId() { + return messageId; + } + + @JsonProperty("messageId") + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + @JsonProperty("text") + public String getText() { + return text; + } + + @JsonProperty("text") + public void setText(String text) { + this.text = text; + } + + @JsonProperty("variables") + public List<String> getVariables() { + return variables; + } + + @JsonProperty("variables") + public void setVariables(List<String> variables) { + this.variables = variables; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/OperationBody.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/OperationBody.java new file mode 100644 index 0000000000..ddd9a454f8 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/OperationBody.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.bulkprocess; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"uri", +"body" +}) +public class OperationBody { + +@JsonProperty("uri") +private String uri; +@JsonProperty("body") +private Object body; + +@JsonProperty("uri") +public String getUri() { +return uri; +} + +@JsonProperty("uri") +public void setUri(String uri) { +this.uri = uri; +} + +public OperationBody withUri(String uri) { +this.uri = uri; +return this; +} + +@JsonProperty("body") +public Object getBody() { +return body; +} + +@JsonProperty("body") +public void setBody(Object body) { +this.body = body; +} + +public OperationBody withBody(Object body) { +this.body = body; +return this; +} + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/Transaction.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/Transaction.java new file mode 100644 index 0000000000..8c4d54dc16 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/Transaction.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.bulkprocess; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"patch", +"patch", +"delete" +}) +public class Transaction { + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonProperty("put") +private List<OperationBody> put = new ArrayList<>(); + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonProperty("patch") +private List<OperationBody> patch = new ArrayList<>(); + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonProperty("delete") +private List<OperationBody> delete = new ArrayList<>(); + +@JsonProperty("put") +public List<OperationBody> getPut() { +return put; +} + +@JsonProperty("put") +public void setPut(List<OperationBody> put) { +this.put = put; +} + +public Transaction withPut(List<OperationBody> put) { +this.put = put; +return this; +} + +@JsonProperty("patch") +public List<OperationBody> getPatch() { +return patch; +} + +@JsonProperty("patch") +public void setPatch(List<OperationBody> patch) { +this.patch = patch; +} + +public Transaction withPatch(List<OperationBody> patch) { +this.patch = patch; +return this; +} + +@JsonProperty("delete") +public List<OperationBody> getDelete() { +return delete; +} + +@JsonProperty("delete") +public void setDelete(List<OperationBody> delete) { +this.delete = delete; +} + +public Transaction withDelete(List<OperationBody> delete) { +this.delete = delete; +return this; +} + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/Transactions.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/Transactions.java new file mode 100644 index 0000000000..f6ce3c5d2c --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/bulkprocess/Transactions.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.bulkprocess; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"transactions" +}) +public class Transactions { + +@JsonProperty("transactions") +private List<Transaction> transactions = new ArrayList<>(); + +@JsonProperty("transactions") +public List<Transaction> getTransactions() { +return transactions; +} + +@JsonProperty("transactions") +public void setTransactions(List<Transaction> transactions) { +this.transactions = transactions; +} + +public Transactions withTransactions(List<Transaction> transactions) { +this.transactions = transactions; +return this; +} + +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIResourceUri.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIResourceUri.java new file mode 100644 index 0000000000..36e3d008ae --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIResourceUri.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +import org.openecomp.mso.client.aai.AAIObjectPlurals; +import org.openecomp.mso.client.aai.AAIObjectType; + +public interface AAIResourceUri extends AAIUri { + + public AAIResourceUri relationshipAPI(); + public AAIResourceUri relatedTo(AAIObjectPlurals plural); + public AAIResourceUri relatedTo(AAIObjectType type, String... values); + public AAIResourceUri resourceVersion(String version); + public AAIResourceUri depth(Depth depth); + public AAIResourceUri nodesOnly(boolean nodesOnly); + public AAIResourceUri queryParam(String name, String... values); + public AAIResourceUri clone(); +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIUri.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIUri.java new file mode 100644 index 0000000000..1617bcddea --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIUri.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +import java.net.URI; +import java.util.Map; + +import org.openecomp.mso.client.aai.AAIObjectPlurals; +import org.openecomp.mso.client.aai.AAIObjectType; + +public interface AAIUri { + + public URI build(); + /** + * By default A&AI enforces a depth of 1. Some objects can be told to retrieve objects + * nested beneath them by increasing this number. + * + * You can use 0 to restrict the returned information to only the object you requested + * You can use all to retrieve all nested objects (this should only be used if you really need a massive amount of information and are caching the retrieval) + * @param depth + * @return + */ + public AAIUri depth(Depth depth); + /** + * Makes client only return object fields, no relationships + * + * @return + */ + public AAIUri nodesOnly(boolean nodesOnly); + public AAIUri queryParam(String name, String... values); + public AAIUri clone(); + + /** + * returns all key values of the URI as a map. Key names can be found in {@link AAIObjectType} + * @return + */ + public Map<String, String> getURIKeys(); + public AAIObjectType getObjectType(); + public boolean equals(Object o); +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactory.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactory.java new file mode 100644 index 0000000000..cb33435c69 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactory.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +import java.net.URI; + +import org.openecomp.mso.client.aai.AAIObjectPlurals; +import org.openecomp.mso.client.aai.AAIObjectType; + + +public class AAIUriFactory { + + /** + * values are filled into the URI template specified in {@link AAIObjectType} in order + * + * @param type + * @param values + * @return + */ + public static AAIResourceUri createResourceUri(AAIObjectType type, Object... values) { + if (AAIObjectType.SERVICE_INSTANCE.equals(type)) { + return new ServiceInstanceUri(values); + } else { + return new SimpleUri(type, values); + } + } + + public static AAIResourceUri createNodesUri(AAIObjectType type, Object... values) { + return new NodesUri(type, values); + + } + + /** + * This method should only be used to wrap a URI retrieved from A&AI contained within an object response + * + * @param type + * @param uri + * @return + */ + public static AAIResourceUri createResourceFromExistingURI(AAIObjectType type, URI uri) { + return new SimpleUri(type, uri); + } + + /** + * Creates a uri for a plural type e.g. /cloud-infrastructure/pservers + * + * @param type + * @return + */ + public static AAIResourceUri createResourceUri(AAIObjectPlurals type) { + + return new SimpleUri(type); + + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/Depth.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/Depth.java new file mode 100644 index 0000000000..7522ea33d1 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/Depth.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +public enum Depth { + ZERO("0"), + ONE("1"), + TWO("2"), + THREE("3"), + FOUR("4"), + FIVE("5"), + SIX("6"), + ALL("all"); + + private final String depth; + private Depth(String s) { + + this.depth = s; + } + + + @Override + public String toString() { + return this.depth; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/NodesUri.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/NodesUri.java new file mode 100644 index 0000000000..407e0ecc9e --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/NodesUri.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +import javax.ws.rs.core.UriBuilder; + +import org.openecomp.mso.client.aai.AAIObjectPlurals; +import org.openecomp.mso.client.aai.AAIObjectType; + +public class NodesUri extends SimpleUri { + + protected NodesUri(AAIObjectType type, Object... values) { + super(type, values); + } + + + @Override + protected String getTemplate(AAIObjectType type) { + return "/nodes" + type.partialUri(); + } + + @Override + protected String getTemplate(AAIObjectPlurals type) { + return "/nodes" + type.partialUri(); + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUri.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUri.java new file mode 100644 index 0000000000..cdaecedfa9 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUri.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +import java.io.IOException; +import java.net.URI; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; + +import javax.ws.rs.BadRequestException; +import javax.ws.rs.client.ResponseProcessingException; +import javax.ws.rs.core.UriBuilder; + +import org.openecomp.mso.client.aai.AAIObjectType; +import org.openecomp.mso.client.aai.AAIQueryClient; +import org.openecomp.mso.client.aai.Format; +import org.openecomp.mso.client.aai.entities.CustomQuery; +import org.openecomp.mso.client.aai.entities.Results; +import org.openecomp.mso.client.aai.exceptions.AAIPayloadException; +import org.openecomp.mso.client.aai.exceptions.AAIUriComputationException; +import org.openecomp.mso.client.aai.exceptions.AAIUriNotFoundException; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceInstanceUri extends SimpleUri { + + private Optional<String> cachedValue = Optional.empty(); + + protected ServiceInstanceUri(Object... values) { + super(AAIObjectType.SERVICE_INSTANCE, values); + } + protected ServiceInstanceUri(UriBuilder builder, Optional<String> cachedValue, Object... values) { + super(AAIObjectType.SERVICE_INSTANCE, builder, values); + this.cachedValue = cachedValue; + } + protected String getSerivceInstance(Object id) throws AAIUriNotFoundException, AAIPayloadException { + if (!this.getCachedValue().isPresent()) { + AAIResourceUri serviceInstanceUri = AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE, id); + CustomQuery query = new CustomQuery(Collections.singletonList(serviceInstanceUri)); + String resultJson; + try { + resultJson = this.getQueryClient().query(Format.PATHED, query); + } catch (ResponseProcessingException e) { + if (e.getCause() instanceof BadRequestException) { + throw new AAIUriNotFoundException("Service instance " + id + " not found at: " + serviceInstanceUri.build()); + } else { + throw e; + } + } + try { + cachedValue = extractRelatedLink(resultJson); + if (!cachedValue.isPresent()) { + throw new AAIUriNotFoundException("Service instance " + id + " not found at: " + serviceInstanceUri.build()); + } + } catch (IOException e) { + throw new AAIPayloadException("could not map payload: " + resultJson, e); + } + + } + + return this.getCachedValue().get(); + } + + protected Optional<String> extractRelatedLink(String jsonString) throws IOException { + Optional<String> result; + ObjectMapper mapper = new ObjectMapper(); + + Results<Map<String, String>> results = mapper.readValue(jsonString, new TypeReference<Results<Map<String, String>>>(){}); + if (results.getResult().size() == 1) { + String uriString = results.getResult().get(0).get("resource-link"); + URI uri = UriBuilder.fromUri(uriString).build(); + String rawPath = uri.getRawPath(); + result = Optional.of(rawPath.replaceAll("/aai/v\\d+", "")); + } else if (results.getResult().isEmpty()) { + result = Optional.empty(); + } else { + throw new IllegalStateException("more than one result returned"); + } + + return result; + } + + protected Optional<String> getCachedValue() { + return this.cachedValue; + } + + @Override + public URI build() { + try { + if (this.values.length == 1) { + String uri = getSerivceInstance(this.values[0]); + Map<String, String> map = getURIKeys(uri); + return super.build(map.values().toArray(values)); + } + } catch (AAIUriNotFoundException | AAIPayloadException e) { + throw new AAIUriComputationException(e); + } + return super.build(); + } + + @Override + public ServiceInstanceUri clone() { + return new ServiceInstanceUri(this.internalURI.clone(), this.getCachedValue(), values); + } + + protected AAIQueryClient getQueryClient() { + return new AAIQueryClient(); + } +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java new file mode 100644 index 0000000000..f3e6fad48b --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.UriBuilder; + +import org.openecomp.mso.client.aai.AAIObjectPlurals; +import org.openecomp.mso.client.aai.AAIObjectType; +import org.openecomp.mso.client.aai.entities.uri.parsers.UriParser; +import org.openecomp.mso.client.aai.entities.uri.parsers.UriParserSpringImpl; +import org.springframework.web.util.UriUtils; + +public class SimpleUri implements AAIResourceUri { + + protected UriBuilder internalURI; + protected final static String relationshipAPI = "/relationship-list/relationship"; + protected final static String relatedTo = "/related-to"; + protected final Object[] values; + protected final AAIObjectType type; + protected final AAIObjectPlurals pluralType; + protected SimpleUri(AAIObjectType type, Object... values) { + this.type = type; + this.pluralType = null; + this.internalURI = UriBuilder.fromPath(this.getTemplate(type)); + this.values = values; + } + protected SimpleUri(AAIObjectType type, URI uri) { + this.type = type; + this.pluralType = null; + this.internalURI = UriBuilder.fromPath(uri.getRawPath().replaceAll("/aai/v\\d+", "")); + this.values = new Object[0]; + } + protected SimpleUri(AAIObjectType type, UriBuilder builder, Object... values) { + this.internalURI = builder; + this.values = values; + this.type = type; + this.pluralType = null; + } + protected SimpleUri(AAIObjectPlurals type, UriBuilder builder, Object... values) { + this.internalURI = builder; + this.values = values; + this.type = null; + this.pluralType = type; + } + protected SimpleUri(AAIObjectPlurals type) { + this.type = null; + this.pluralType = type; + this.internalURI = UriBuilder.fromPath(this.getTemplate(type)); + this.values = new Object[0]; + } + + @Override + public SimpleUri relationshipAPI() { + this.internalURI = internalURI.path(relationshipAPI); + return this; + } + + @Override + public SimpleUri relatedTo(AAIObjectPlurals plural) { + + this.internalURI = internalURI.path(relatedTo).path(plural.partialUri()); + return this; + } + @Override + public SimpleUri relatedTo(AAIObjectType type, String... values) { + this.internalURI = internalURI.path(relatedTo).path(UriBuilder.fromPath(type.partialUri()).build(values).toString()); + return this; + } + + @Override + public SimpleUri resourceVersion(String version) { + this.internalURI = internalURI.queryParam("resource-version", version); + return this; + } + + @Override + public SimpleUri queryParam(String name, String... values) { + this.internalURI = internalURI.queryParam(name, values); + return this; + } + + @Override + public URI build() { + return build(this.values); + } + + protected URI build(Object... values) { + //This is a workaround because resteasy does not encode URIs correctly + final String[] encoded = new String[values.length]; + for (int i = 0; i < values.length; i++) { + try { + encoded[i] = UriUtils.encode(values[i].toString(), StandardCharsets.UTF_8.toString()); + } catch (UnsupportedEncodingException e) { + encoded[i] = values[i].toString(); + } + } + return internalURI.buildFromEncoded(encoded); + } + + @Override + public Map<String, String> getURIKeys() { + return this.getURIKeys(this.build().toString()); + } + + protected Map<String, String> getURIKeys(String uri) { + UriParser parser; + if (this.type != null) { + if (!("".equals(this.getTemplate(type)))) { + parser = new UriParserSpringImpl(this.getTemplate(type)); + } else { + return new HashMap<>(); + } + } else { + parser = new UriParserSpringImpl(this.getTemplate(pluralType)); + } + + + return parser.parse(uri); + } + + @Override + public SimpleUri clone() { + if (this.type != null) { + return new SimpleUri(this.type, this.internalURI.clone(), values); + } else { + return new SimpleUri(this.pluralType, this.internalURI.clone(), values); + } + } + + @Override + public AAIObjectType getObjectType() { + return this.type; + } + + @Override + public boolean equals(Object o) { + if (o instanceof AAIUri) { + return this.build().equals(((AAIUri)o).build()); + } + return false; + } + @Override + public SimpleUri depth(Depth depth) { + this.internalURI.queryParam("depth", depth.toString()); + return this; + } + @Override + public SimpleUri nodesOnly(boolean nodesOnly) { + if (nodesOnly) { + this.internalURI.queryParam("nodes-only", ""); + } + return this; + } + + protected String getTemplate(AAIObjectType type) { + return type.uriTemplate(); + } + + protected String getTemplate(AAIObjectPlurals type) { + return type.uriTemplate(); + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParser.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParser.java new file mode 100644 index 0000000000..8e37d595b0 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParser.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri.parsers; + +import java.util.Map; +import java.util.Set; + +public interface UriParser { + public Set<String> getVariables(); + public Map<String, String> parse(final String uri); +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImpl.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImpl.java new file mode 100644 index 0000000000..75f9005125 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImpl.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.aai.entities.uri.parsers; +import java.io.UnsupportedEncodingException; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.springframework.web.util.UriTemplate; +import org.springframework.web.util.UriUtils; + +public class UriParserSpringImpl implements UriParser { + + private final UriTemplate uriTemplate; + + public UriParserSpringImpl(final String template) { + this.uriTemplate = new UriTemplate(template); + } + + @Override + public Map<String, String> parse(final String uri) { + final boolean match = this.uriTemplate.matches(uri); + if (!match) { + return new LinkedHashMap<>(); + } + return Collections.unmodifiableMap(decodeParams(this.uriTemplate.match(uri))); + } + + @Override + public Set<String> getVariables() { + return Collections.unmodifiableSet(new LinkedHashSet<String>(this.uriTemplate.getVariableNames())); + } + + protected Map<String, String> decodeParams(Map<String, String> map) { + final Map<String, String> result = new LinkedHashMap<>(); + + for (Entry<String, String> entry : map.entrySet()) { + try { + result.put(entry.getKey(), UriUtils.decode(entry.getValue(), "UTF-8")); + } catch (UnsupportedEncodingException e) { + result.put(entry.getKey(), ""); + } + } + + return result; + } +}
\ No newline at end of file |