diff options
author | sheetalm <sheetal.mudholkar@amdocs.com> | 2018-02-20 19:06:27 +0530 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2018-03-08 08:50:18 +0000 |
commit | 297209b45b403e9b314ebeb1140886e00ffd3f6d (patch) | |
tree | a8ba88380016fed0d1f28fbddfc4d4909ca22165 /services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java | |
parent | 2b60bd08c6b209c0817fac84970c35df4abca6ed (diff) |
Activity Spec Service - Implementation
Correcting error message.
InternalEmptyObject not required to be serializable.
Fixed review comments on Patch Set 10. Not all fixed
Adding services profile in main sdc pom.Moving Static imports at end.
Patch Set 7 changes
Patch Set 6 - Removing javax.inject. Remove user from interface and
Changing scope to be singleton. Correcting error message
Patch Set 4 Not fixing Spring related review comments in this patch set
Patch Set 4 Fixed review comments related to unused dependency
Fixed review comments for plugin version. Corrected License
Adding Activity Spec Service Implementation
Not adding to main sdc pom as of now
Change-Id: I5285c0ab3b71b492d18ca442ebd52b59ab0eabdc
Issue-ID: SDC-1048
Signed-off-by: sheetalm <sheetal.mudholkar@amdocs.com>
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java')
-rw-r--r-- | services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java new file mode 100644 index 0000000000..d9d495a01a --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java @@ -0,0 +1,151 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * 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. + */ + +package org.openecomp.activityspec.be.dao.impl; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; + +import org.openecomp.activityspec.be.dao.ActivitySpecDao; +import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; +import org.openecomp.activityspec.utils.ActivitySpecConstant; +import org.openecomp.activityspec.be.datatypes.ActivitySpecData; +import org.openecomp.activityspec.be.datatypes.ElementType; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + +public class ActivitySpecDaoZusammenImpl implements ActivitySpecDao { + + private final ZusammenAdaptor zusammenAdaptor; + + public ActivitySpecDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void create(ActivitySpecEntity entity) { + SessionContext context = createSessionContext(); + ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.CREATE); + + ElementContext elementContext = + new ElementContext(entity.getId(), entity.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, generalElement, + "Create Activity Spec General Info Element"); + } + + @Override + public ActivitySpecEntity get(ActivitySpecEntity entity) { + SessionContext context = createSessionContext(); + + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); + Optional<Element> element = zusammenAdaptor.getElementByName(context, elementContext, + null, ElementType.ACTIVITYSPEC.name()); + if (element.isPresent()) { + return mapZusammenElementToActivityDetails(element.get()); + } else { + return null; + } + } + + @Override + public void update(ActivitySpecEntity entity) { + SessionContext context = createSessionContext(); + ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.UPDATE); + + ElementContext elementContext = + new ElementContext(entity.getId(), entity.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, generalElement, + "Update Activity Spec General Info Element"); + } + + + private ActivitySpecEntity mapZusammenElementToActivityDetails(Element element) { + ActivitySpecEntity entity = new ActivitySpecEntity(); + entity.setId(element.getElementId().getValue()); + enrichEntityFromElementData(entity, element.getData()); + enrichEntityFromElementInfo(entity, element.getInfo()); + return entity; + } + + private ZusammenElement mapActivityDetailsToZusammenElement(ActivitySpecEntity entity, + Action action) { + ZusammenElement generalElement = + buildStructuralElement(ElementType.ACTIVITYSPEC.name(), action); + + enrichElementInfoFromEntity(generalElement, entity); + enrichElementDataFromEntity(generalElement, entity); + return generalElement; + } + + + private void enrichEntityFromElementInfo(ActivitySpecEntity entity, Info info) { + entity.setName(info.getProperty(InfoPropertyName.NAME.getValue())); + entity.setDescription(info.getProperty(InfoPropertyName.DESCRIPTION.getValue())); + entity.setCategoryList(info.getProperty(InfoPropertyName.CATEGORY.getValue())); + } + + private void enrichEntityFromElementData(ActivitySpecEntity entity, InputStream data) { + ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class); + if (Objects.nonNull(activitySpecData)) { + entity.setInputParameters(activitySpecData.getInputParameters()); + entity.setOutputParameters(activitySpecData.getOutputParameters()); + } + } + + private void enrichElementInfoFromEntity(ZusammenElement element, ActivitySpecEntity entity) { + element.getInfo().addProperty(InfoPropertyName.DESCRIPTION.getValue(), entity.getDescription()); + element.getInfo().addProperty(InfoPropertyName.NAME.getValue(), entity.getName()); + element.getInfo().addProperty(InfoPropertyName.CATEGORY.getValue(), + entity.getCategoryList()); + } + + + private void enrichElementDataFromEntity(ZusammenElement element, ActivitySpecEntity entity) { + ActivitySpecData activitySpecData = new ActivitySpecData(); + activitySpecData.setInputParameters(entity.getInputParameters()); + activitySpecData.setOutputParameters(entity.getOutputParameters()); + element.setData(new ByteArrayInputStream(JsonUtil.object2Json(activitySpecData).getBytes())); + } + + public enum InfoPropertyName { + DESCRIPTION("description"), + NAME("name"), + CATEGORY(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME); + + private final String value; + + InfoPropertyName(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + +} |