From b909d1e85f13431436808e6880a1e857addb449c Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 23 Dec 2019 09:44:11 +0200 Subject: Add request-summary field to ServiceInfo Issue-ID: VID-724 Change-Id: Ifdf39a0c21e7a96065f88aa2aa4a5560e0559564 Signed-off-by: Ittay Stern --- .../src/main/resources/db.changelog-01.sql | 5 ++ .../main/java/org/onap/vid/model/ServiceInfo.java | 32 +++++++--- .../AsyncInstantiationBusinessLogicImpl.java | 3 +- .../src/main/java/org/onap/vid/utils/DaoUtils.java | 51 ++++++++++++++-- .../java/org/onap/vid/model/ServiceInfoTest.java | 58 ++++++++++++++++++ .../DaoUtilsStringToLongMapAttributeConverter.java | 69 ++++++++++++++++++++++ 6 files changed, 206 insertions(+), 12 deletions(-) create mode 100644 vid-app-common/src/test/java/org/onap/vid/model/ServiceInfoTest.java create mode 100644 vid-app-common/src/test/java/org/onap/vid/utils/DaoUtilsStringToLongMapAttributeConverter.java diff --git a/epsdk-app-onap/src/main/resources/db.changelog-01.sql b/epsdk-app-onap/src/main/resources/db.changelog-01.sql index acc061796..9a24692a9 100644 --- a/epsdk-app-onap/src/main/resources/db.changelog-01.sql +++ b/epsdk-app-onap/src/main/resources/db.changelog-01.sql @@ -318,3 +318,8 @@ INSERT IGNORE `fn_user_role` VALUES (1,20,NULL,1); INSERT IGNORE `fn_user_role` VALUES (1,21,NULL,1); INSERT IGNORE `fn_user_role` VALUES (1,22,NULL,1); UPDATE `fn_app` SET `APP_IMAGE_URL`=null,`APP_URL`=null,`APP_ALTERNATE_URL`=null WHERE `APP_ID`=1; + + +--changeset vid:service_info_request_summary +ALTER TABLE `vid_openecomp_epsdk`.`vid_service_info` + ADD COLUMN `REQUEST_SUMMARY` VARCHAR(400) NULL DEFAULT NULL COLLATE 'utf8_bin'; diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java index 85c83eb98..677d67c8e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java @@ -24,10 +24,12 @@ package org.onap.vid.model; import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; import java.util.Date; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -41,6 +43,8 @@ import org.hibernate.annotations.SelectBeforeUpdate; import org.hibernate.annotations.Type; import org.onap.portalsdk.core.domain.support.DomainVo; import org.onap.vid.job.Job; +import org.onap.vid.job.Job.JobStatus; +import org.onap.vid.utils.DaoUtils.StringToLongMapAttributeConverter; /* The following 2 annotations let hibernate to update only fields that actually have been changed. @@ -91,17 +95,19 @@ public class ServiceInfo extends DomainVo { private String serviceModelVersion; private Date createdBulkDate; private ServiceAction action; + private Map requestSummary; public ServiceInfo(){ } - public ServiceInfo(String userId, Boolean aLaCarte, Job.JobStatus jobStatus, boolean pause, UUID jobId, UUID templateId, - String owningEntityId, String owningEntityName, String project, String aicZoneId, String aicZoneName, - String tenantId, String tenantName, String regionId, String regionName, String serviceType, - String subscriberName, String subscriberId, String serviceInstanceId, String serviceInstanceName, - String serviceModelId, String serviceModelName, String serviceModelVersion, Date createdBulkDate, - ServiceAction action, boolean retryEnabled) { + public ServiceInfo(String userId, Boolean aLaCarte, JobStatus jobStatus, boolean pause, UUID jobId, + UUID templateId, + String owningEntityId, String owningEntityName, String project, String aicZoneId, String aicZoneName, + String tenantId, String tenantName, String regionId, String regionName, String serviceType, + String subscriberName, String subscriberId, String serviceInstanceId, String serviceInstanceName, + String serviceModelId, String serviceModelName, String serviceModelVersion, Date createdBulkDate, + ServiceAction action, boolean retryEnabled, Map requestSummary) { this.userId = userId; this.aLaCarte = aLaCarte; this.jobStatus = jobStatus; @@ -128,6 +134,7 @@ public class ServiceInfo extends DomainVo { this.createdBulkDate = createdBulkDate; this.action = action; this.retryEnabled = retryEnabled; + this.requestSummary = requestSummary; } @Column(name = "JOB_ID", columnDefinition = "CHAR(36)") @@ -287,6 +294,12 @@ public class ServiceInfo extends DomainVo { return action; } + @Column(name="REQUEST_SUMMARY") + @Convert(converter = StringToLongMapAttributeConverter.class) + public Map getRequestSummary() { + return requestSummary; + } + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Override @@ -454,6 +467,10 @@ public class ServiceInfo extends DomainVo { public void setAction(ServiceAction action) { this.action = action; } + public void setRequestSummary(Map requestSummary) { + this.requestSummary = requestSummary; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -488,6 +505,7 @@ public class ServiceInfo extends DomainVo { Objects.equals(getServiceModelName(), that.getServiceModelName()) && Objects.equals(getServiceModelVersion(), that.getServiceModelVersion()) && Objects.equals(getCreatedBulkDate(), that.getCreatedBulkDate()) && + Objects.equals(getRequestSummary(), that.getRequestSummary()) && getAction() == that.getAction(); } @@ -497,6 +515,6 @@ public class ServiceInfo extends DomainVo { getStatusModifiedDate(), isHidden(), isPause(), isRetryEnabled(), getDeletedAt(), getOwningEntityId(), getOwningEntityName(), getProject(), getAicZoneId(), getAicZoneName(), getTenantId(), getTenantName(), getRegionId(), getRegionName(), getServiceType(), getSubscriberName(), getSubscriberId(), getServiceInstanceId(), getServiceInstanceName(), getServiceModelId(), getServiceModelName(), - getServiceModelVersion(), getCreatedBulkDate(), getAction()); + getServiceModelVersion(), getCreatedBulkDate(), getAction(), getRequestSummary()); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java index 787ad1262..6729bdac8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java @@ -266,7 +266,8 @@ public class AsyncInstantiationBusinessLogicImpl implements serviceInstantiation.getModelInfo().getModelVersion(), createdBulkDate, serviceAction, - false); + false, + null); } @Override diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java b/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java index 7d3b926ea..7fb03aea8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java @@ -20,14 +20,21 @@ package org.onap.vid.utils; +import static java.util.Objects.isNull; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import javax.persistence.AttributeConverter; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; -import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.portalsdk.core.domain.FusionObject; - -import java.util.HashMap; -import java.util.function.Function; +import org.onap.vid.exceptions.GenericUncheckedException; public class DaoUtils { @@ -70,4 +77,40 @@ public class DaoUtils { props.put(FusionObject.Parameters.PARAM_USERID, 0); return props; } + + public static class StringToLongMapAttributeConverter extends JsonAttributeConverter> { + + private final TypeReference> typeReference = + new TypeReference>() {}; + + @Override + public TypeReference> getTypeReference() { + return typeReference; + } + } + + private static abstract class JsonAttributeConverter implements AttributeConverter { + + abstract public TypeReference getTypeReference(); + + @Override + public String convertToDatabaseColumn(T attribute) { + try { + return isNull(attribute) ? null + : JACKSON_OBJECT_MAPPER.writeValueAsString(attribute); + } catch (JsonProcessingException e) { + return ExceptionUtils.rethrow(e); + } + } + + @Override + public T convertToEntityAttribute(String dbData) { + try { + return isNull(dbData) ? null + : JACKSON_OBJECT_MAPPER.readValue(dbData, getTypeReference()); + } catch (JsonProcessingException e) { + return ExceptionUtils.rethrow(e); + } + } + } } diff --git a/vid-app-common/src/test/java/org/onap/vid/model/ServiceInfoTest.java b/vid-app-common/src/test/java/org/onap/vid/model/ServiceInfoTest.java new file mode 100644 index 000000000..23391cabd --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/model/ServiceInfoTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 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.onap.vid.model; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.onap.vid.testUtils.TestUtils.allPropertiesOf; + +import org.onap.portalsdk.core.domain.support.DomainVo; +import org.testng.annotations.Test; + +public class ServiceInfoTest { + final private String[] excludedProperties = allPropertiesOf(DomainVo.class); + + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(ServiceInfo.class, hasValidGettersAndSetters()); + } + + @Test + public void shouldHaveValidBeanConstructor() { + assertThat(ServiceInfo.class, hasValidBeanConstructor()); + } + + @Test + public void shouldHaveValidBeanHashCode() { + assertThat(ServiceInfo.class, hasValidBeanHashCodeExcluding(excludedProperties)); + } + + @Test + public void shouldHaveValidBeanEquals() { + assertThat(ServiceInfo.class, hasValidBeanEqualsExcluding(excludedProperties)); + } + +} + + diff --git a/vid-app-common/src/test/java/org/onap/vid/utils/DaoUtilsStringToLongMapAttributeConverter.java b/vid-app-common/src/test/java/org/onap/vid/utils/DaoUtilsStringToLongMapAttributeConverter.java new file mode 100644 index 000000000..e71f75bb3 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/utils/DaoUtilsStringToLongMapAttributeConverter.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 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.onap.vid.utils; + +import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +import com.google.common.collect.ImmutableMap; +import org.onap.vid.utils.DaoUtils.StringToLongMapAttributeConverter; +import org.testng.annotations.Test; + +public class DaoUtilsStringToLongMapAttributeConverter { + + private final StringToLongMapAttributeConverter stringToLongMapAttributeConverter = new StringToLongMapAttributeConverter(); + + @Test + public void toEntity_givenNullString_yieldNullMap() { + assertThat( + stringToLongMapAttributeConverter.convertToEntityAttribute(null), + is(nullValue())); + } + + @Test + public void toEntity_givenValidString_yieldGoodMap() { + assertThat( + stringToLongMapAttributeConverter.convertToEntityAttribute("{\"a\": 5}"), + is(ImmutableMap.of("a", 5L))); + } + + @Test(expectedExceptions = Exception.class) + public void toEntity_givenBadString_throws() { + stringToLongMapAttributeConverter.convertToEntityAttribute("{a: not-good}"); + } + + @Test + public void fromEntity_givenNullMap_yieldNullString() { + assertThat( + stringToLongMapAttributeConverter.convertToDatabaseColumn(null), + is(nullValue())); + } + + @Test + public void fromEntity_givenValidMap_yieldString() { + assertThat( + stringToLongMapAttributeConverter.convertToDatabaseColumn(ImmutableMap.of("a", 5L)), + jsonEquals("{\"a\": 5}")); + } + +} -- cgit 1.2.3-korg